Skip to content

Commit

Permalink
fix(account): introduce local password validation identical to dhis2-…
Browse files Browse the repository at this point in the history
…core
  • Loading branch information
HendrikThePendric committed May 7, 2019
1 parent f4043f5 commit 6cff458
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/account/AccountEditor.component.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';

import { isValidPassword } from 'd2-ui/lib/forms/Validators';

import FormBuilder from 'd2-ui/lib/forms/FormBuilder.component';
import TextField from 'd2-ui/lib/form-fields/TextField';
import { FlatButton, RaisedButton } from 'material-ui';

import appActions from '../app.actions';
import accountActions from './account.actions';
import isValidPassword from './isValidPassword';


class AccountEditor extends Component {
Expand Down
18 changes: 18 additions & 0 deletions src/account/isValidPassword.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Atleast one digit
const oneDigit = /^(?=.*\d)/;

// Atleast one uppercase character
const oneUpperCase = /^(?=.*[A-Z])/;

// Atleast one special character
// Using this regex to match all non-alphanumeric characters to match server-side implementation
// https://github.com/dhis2/dhis2-core/blob/master/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/SpecialCharacterValidationRule.java#L39
const oneSpecialCharacter = /[^a-zA-Z0-9]/;

export default function isValidPassword(value) {
if (!value) {
return true;
}
return oneDigit.test(value) && oneUpperCase.test(value) && oneSpecialCharacter.test(value) && value.length > 7 && value.length < 36;
}
isValidPassword.message = 'invalid_password';

0 comments on commit 6cff458

Please sign in to comment.