Skip to content

Commit

Permalink
feat: Stronger password policy
Browse files Browse the repository at this point in the history
  • Loading branch information
meltyshev committed Aug 26, 2022
1 parent fd8f40f commit 5c91bdd
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 10 deletions.
Expand Up @@ -7,6 +7,7 @@ import { useDidUpdate, usePrevious, useToggle } from '../../lib/hooks';
import { Input, Popup } from '../../lib/custom-ui';

import { useForm } from '../../hooks';
import { isPassword } from '../../utils/validator';

import styles from './UserPasswordEditStep.module.scss';

Expand Down Expand Up @@ -56,7 +57,7 @@ const UserPasswordEditStep = React.memo(
const currentPasswordField = useRef(null);

const handleSubmit = useCallback(() => {
if (!data.password) {
if (!data.password || !isPassword(data.password)) {
passwordField.current.select();
return;
}
Expand Down Expand Up @@ -112,14 +113,18 @@ const UserPasswordEditStep = React.memo(
)}
<Form onSubmit={handleSubmit}>
<div className={styles.text}>{t('common.newPassword')}</div>
<Input.Password
fluid
ref={passwordField}
name="password"
value={data.password}
className={styles.field}
onChange={handleFieldChange}
/>
<div className={styles.field}>
<Input.Password
fluid
ref={passwordField}
name="password"
value={data.password}
onChange={handleFieldChange}
/>
<div className={styles.note}>
{t('common.mustBeAtLeast6CharactersLongAndContainAtLeastOneLetterAndNumber')}
</div>
</div>
{usePasswordConfirmation && (
<>
<div className={styles.text}>{t('common.currentPassword')}</div>
Expand Down
Expand Up @@ -3,6 +3,12 @@
margin-bottom: 8px;
}

.note {
font-size: 11px;
margin-top: 4px;
opacity: 0.5;
}

.text {
color: #444444;
font-size: 12px;
Expand Down
2 changes: 2 additions & 0 deletions client/src/locales/en/core.js
Expand Up @@ -105,6 +105,8 @@ export default {
members: 'Members',
minutes: 'Minutes',
moveCard_title: 'Move Card',
mustBeAtLeast6CharactersLongAndContainAtLeastOneLetterAndNumber:
'Must be at least 6 characters long and contain at least one letter and number',
name: 'Name',
newEmail: 'New e-mail',
newPassword: 'New password',
Expand Down
2 changes: 2 additions & 0 deletions client/src/locales/ru/core.js
Expand Up @@ -100,6 +100,8 @@ export default {
members: 'Участники',
minutes: 'Минуты',
moveCard: 'Перемещение карточки',
mustBeAtLeast6CharactersLongAndContainAtLeastOneLetterAndNumber:
'Должен быть не менее 6 символов и содержать хотя бы одну букву и цифру',
name: 'Имя',
newEmail: 'Новый e-mail',
newPassword: 'Новый пароль',
Expand Down
6 changes: 5 additions & 1 deletion client/src/utils/validator.js
@@ -1,6 +1,10 @@
const PASSWORD_REGEX = /^(?=.*[A-Za-z])(?=.*\d).+$/;
const USERNAME_REGEX = /^[a-zA-Z0-9]+((_|\.)?[a-zA-Z0-9])*$/;

// eslint-disable-next-line import/prefer-default-export
export const isPassword = (string) => {
return string.length >= 3 && PASSWORD_REGEX.test(string);
};

export const isUsername = (string) => {
return string.length >= 3 && string.length <= 16 && USERNAME_REGEX.test(string);
};
2 changes: 2 additions & 0 deletions server/api/controllers/users/create.js
Expand Up @@ -16,6 +16,8 @@ module.exports = {
},
password: {
type: 'string',
minLength: 6,
regex: /^(?=.*[A-Za-z])(?=.*\d).+$/,
required: true,
},
name: {
Expand Down
2 changes: 2 additions & 0 deletions server/api/controllers/users/update-password.js
Expand Up @@ -18,6 +18,8 @@ module.exports = {
},
password: {
type: 'string',
minLength: 6,
regex: /^(?=.*[A-Za-z])(?=.*\d).+$/,
required: true,
},
currentPassword: {
Expand Down

0 comments on commit 5c91bdd

Please sign in to comment.