From 9ad92b6c04c0ae6a6ae6b53157458dbe7aec23c1 Mon Sep 17 00:00:00 2001 From: hatim dinia Date: Tue, 12 Mar 2024 07:35:02 +0100 Subject: [PATCH] fix(ui-utils): optimize `validatePassword` regex to mitigate potential backtracking issues --- webapp/src/utils/validationUtils.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/webapp/src/utils/validationUtils.ts b/webapp/src/utils/validationUtils.ts index 656d8e17f7..3d771356e6 100644 --- a/webapp/src/utils/validationUtils.ts +++ b/webapp/src/utils/validationUtils.ts @@ -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 (