Skip to content

Commit 207d544

Browse files
fix: address important PR review comments
1 parent 888b500 commit 207d544

4 files changed

Lines changed: 21 additions & 6 deletions

File tree

src/modules/Auth/features/Login/Login.schema.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { checkPassword, getEmailValidationSchema } from 'shared/utils';
77
export const loginFormSchema = () => {
88
const { t } = i18n;
99
const passwordRequired = t('passwordRequired');
10-
const passwordMinLength = t('passwordMinLength', { count: LEGACY_PASSWORD_MIN_LENGTH });
10+
const passwordMinLength = t('passwordMinLength', { chars: LEGACY_PASSWORD_MIN_LENGTH });
1111
const passwordBlankSpaces = t('passwordBlankSpaces');
1212

1313
return yup
@@ -17,7 +17,11 @@ export const loginFormSchema = () => {
1717
password: yup
1818
.string()
1919
.required(passwordRequired)
20-
.min(LEGACY_PASSWORD_MIN_LENGTH, passwordMinLength)
20+
.test(
21+
'min-length',
22+
passwordMinLength,
23+
(password) => !password || checkPassword(password, LEGACY_PASSWORD_MIN_LENGTH).meetsLength,
24+
)
2125
.test(
2226
'no-whitespace',
2327
passwordBlankSpaces,

src/modules/Auth/features/RecoverPassword/RecoverForm/RecoverForm.schema.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ export const newPasswordSchema = () => {
1818
password: yup
1919
.string()
2020
.required(passwordRequired)
21-
.min(ACCOUNT_PASSWORD_MIN_LENGTH, passwordMinLength)
21+
.test(
22+
'min-length',
23+
passwordMinLength,
24+
(password) => !password || checkPassword(password).meetsLength,
25+
)
2226
.test(
2327
'no-whitespace',
2428
passwordBlankSpaces,

src/modules/Auth/features/SignUp/SignUpForm/SignUpForm.schema.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ export const SignUpFormSchema = () => {
2222
password: yup
2323
.string()
2424
.required(passwordRequired)
25-
.min(ACCOUNT_PASSWORD_MIN_LENGTH, passwordMinLength)
25+
.test(
26+
'min-length',
27+
passwordMinLength,
28+
(password) => !password || checkPassword(password).meetsLength,
29+
)
2630
.test(
2731
'no-whitespace',
2832
passwordBlankSpaces,

src/shared/utils/passwordValidation.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import {
1313

1414
export type { PasswordCheckResult };
1515

16-
export const checkPassword = (password: string): PasswordCheckResult => {
16+
export const checkPassword = (
17+
password: string,
18+
minLength: number = ACCOUNT_PASSWORD_MIN_LENGTH,
19+
): PasswordCheckResult => {
1720
const normalized = password.normalize('NFC');
1821
const hasCaselessLetter = CASELESS_LETTER_REGEXP.test(normalized);
1922
const hasUppercase = UPPERCASE_REGEXP.test(normalized) || hasCaselessLetter;
@@ -29,7 +32,7 @@ export const checkPassword = (password: string): PasswordCheckResult => {
2932
hasDigit,
3033
hasSymbol,
3134
hasNoSpaces: VISIBLE_ONLY_REGEXP.test(normalized) && !HIDDEN_BLANKS_REGEXP.test(normalized),
32-
meetsLength: [...normalized].length >= ACCOUNT_PASSWORD_MIN_LENGTH,
35+
meetsLength: [...normalized].length >= minLength,
3336
charTypeCount,
3437
meetsCharTypeRequirement: charTypeCount >= ACCOUNT_PASSWORD_MIN_CHAR_TYPES,
3538
};

0 commit comments

Comments
 (0)