Skip to content

Commit

Permalink
fix(ui-utils): optimize validatePassword regex to mitigate potentia…
Browse files Browse the repository at this point in the history
…l backtracking issues
  • Loading branch information
hdinia committed Mar 12, 2024
1 parent 6a8e418 commit 9ad92b6
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions webapp/src/utils/validationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,28 +127,28 @@ export function validatePassword(
return t("form.field.required");
}

if (!/(?=.*[a-z])/.test(trimmedPassword)) {
return t("form.field.requireLowercase");
if (trimmedPassword.length < 8) {
return t("form.field.minValue", { 0: 8 });
}

if (!/(?=.*[A-Z])/.test(trimmedPassword)) {
return t("form.field.requireUppercase");
if (trimmedPassword.length > 50) {
return t("form.field.maxValue", { 0: 50 });
}

if (!/(?=.*\d)/.test(trimmedPassword)) {
return t("form.field.requireDigit");
if (!/[a-z]/.test(trimmedPassword)) {
return t("form.field.requireLowercase");
}

if (!/(?=.*[^\w\s])/.test(trimmedPassword)) {
return t("form.field.requireSpecialChars");
if (!/[A-Z]/.test(trimmedPassword)) {
return t("form.field.requireUppercase");
}

if (trimmedPassword.length < 8) {
return t("form.field.minValue", { 0: 8 });
if (!/\d/.test(trimmedPassword)) {
return t("form.field.requireDigit");
}

if (trimmedPassword.length > 30) {
return t("form.field.maxValue", { 0: 30 });
if (!/[^\w\s]/.test(trimmedPassword)) {
return t("form.field.requireSpecialChars");
}

if (
Expand Down

0 comments on commit 9ad92b6

Please sign in to comment.