From 43db2f2fba1d85c1e7fb4ebae51ed2a8f04364a9 Mon Sep 17 00:00:00 2001 From: Shubham Kumar Date: Tue, 13 Jan 2026 00:20:08 +0530 Subject: [PATCH] WEB-562:fix(auth) align password validation with backend regex requirements (#2990) fix the grammar --- src/app/core/utils/password.validator.ts | 14 ++++++++++---- src/app/core/utils/passwords-utility.ts | 3 +-- .../change-password-dialog.component.ts | 2 +- .../users/create-user/create-user.component.ts | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/app/core/utils/password.validator.ts b/src/app/core/utils/password.validator.ts index cd83fce01..270694ed7 100644 --- a/src/app/core/utils/password.validator.ts +++ b/src/app/core/utils/password.validator.ts @@ -31,11 +31,17 @@ export function passwordValidator(): ValidatorFn { if (!/\d/.test(value)) { errors['number'] = 'Password must contain at least one number'; } - if (!/^(?:(.)(?!\1))+$/.test(value)) { - errors['repeated'] = 'Password must have not consecutive repeating characters'; + // Check for consecutive repeating characters (e.g., aa, 11, @@) + if (/(.)\1/.test(value)) { + errors['repeated'] = 'Password must not have consecutive repeating characters'; } - if (!/[@$!%*?&]/.test(value)) { - errors['specialChar'] = 'Password must contain at least one special character (@$!%*?&)'; + // Check for any special character (non-alphanumeric, non-space) + if (!/[^\w\s]/.test(value)) { + errors['specialChar'] = 'Password must contain at least one special character'; + } + // Check for spaces + if (/\s/.test(value)) { + errors['spaces'] = 'Password must not contain spaces'; } return Object.keys(errors).length > 0 ? errors : null; diff --git a/src/app/core/utils/passwords-utility.ts b/src/app/core/utils/passwords-utility.ts index 46352299c..f14daca62 100644 --- a/src/app/core/utils/passwords-utility.ts +++ b/src/app/core/utils/passwords-utility.ts @@ -17,9 +17,8 @@ import { environment } from '../../../environments/environment'; }) export class PasswordsUtility { minPasswordLength: number = environment.minPasswordLength | 12; - // password regex pattern public static PASSWORD_REGEX = - '^(?!.*(.)\\1{1,})(?!.*\\s)(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^\\w\\s]).{' + + '^(?!.*(.)\\1)(?!.*\\s)(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^\\w\\s]).{' + (environment.minPasswordLength | 12) + ',50}$'; diff --git a/src/app/zitadel/shared/change-password-dialog/change-password-dialog.component.ts b/src/app/zitadel/shared/change-password-dialog/change-password-dialog.component.ts index 8d2605eff..d8c607dee 100644 --- a/src/app/zitadel/shared/change-password-dialog/change-password-dialog.component.ts +++ b/src/app/zitadel/shared/change-password-dialog/change-password-dialog.component.ts @@ -60,7 +60,7 @@ export class ChangePasswordDialogComponent implements OnInit { Validators.required, Validators.minLength(this.minPasswordLength), Validators.maxLength(50), - Validators.pattern(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\W_]).+$/) + Validators.pattern(/^(?!.*(.)\1)(?!.*\s)(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\w\s]).+$/) ] ], repeatPassword: [ diff --git a/src/app/zitadel/users/create-user/create-user.component.ts b/src/app/zitadel/users/create-user/create-user.component.ts index 2105ddced..6f4ef9e15 100644 --- a/src/app/zitadel/users/create-user/create-user.component.ts +++ b/src/app/zitadel/users/create-user/create-user.component.ts @@ -149,7 +149,7 @@ export class CreateUserComponent implements OnInit, AfterViewInit { Validators.required, Validators.minLength(12), Validators.maxLength(50), - Validators.pattern(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\W_]).+$/) + Validators.pattern(/^(?!.*(.)\1)(?!.*\s)(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\w\s]).+$/) ] ], repeatPassword: [