Skip to content

Commit 7a9c25e

Browse files
authored
WEB-628: Standardize password validation using environment-driven min length and regex configuration (#3234)
WEB-628: Sanitize minPasswordLength to positive integer
1 parent 33cd601 commit 7a9c25e

File tree

20 files changed

+58
-24
lines changed

20 files changed

+58
-24
lines changed

src/app/core/utils/passwords-utility.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import { environment } from '../../../environments/environment';
1616
providedIn: 'root'
1717
})
1818
export class PasswordsUtility {
19-
minPasswordLength: number = environment.minPasswordLength || 12;
20-
public static PASSWORD_REGEX =
21-
'^(?!.*(.)\\1)(?!.*\\s)(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^\\w\\s]).{' +
22-
(environment.minPasswordLength || 12) +
23-
',50}$';
19+
minPasswordLength: number = environment.minPasswordLength;
20+
private static readonly DEFAULT_PASSWORD_REGEX =
21+
'^(?!.*(.)\\1)(?!.*\\s)(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^\\w\\s]).{8,50}$';
22+
23+
public static PASSWORD_REGEX = environment.passwordRegex || PasswordsUtility.DEFAULT_PASSWORD_REGEX;
2424

2525
public getPasswordValidators(): ValidatorFn[] {
2626
return [

src/app/login/login-form/login-form.component.html

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,19 @@
5757
@if (loginForm.controls.password.hasError('required')) {
5858
<mat-error>
5959
{{ 'labels.inputs.Password' | translate }}
60-
<strong>{{ 'labels.commons.pass is required' | translate }}</strong>
60+
<strong>
61+
{{ 'labels.commons.pass is required' | translate: { min: minPasswordLength } }}
62+
</strong>
63+
</mat-error>
64+
} @else if (loginForm.controls.password.hasError('minlength')) {
65+
<mat-error>
66+
{{
67+
'Password is required'
68+
| translate
69+
: {
70+
min: loginForm.controls.password.errors?.minlength?.requiredLength
71+
}
72+
}}
6173
</mat-error>
6274
}
6375
</mat-form-field>

src/app/login/login-form/login-form.component.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { environment } from '../../../environments/environment';
4343
export class LoginFormComponent implements OnInit {
4444
private formBuilder = inject(FormBuilder);
4545
private authenticationService = inject(AuthenticationService);
46+
minPasswordLength = environment.minPasswordLength;
4647

4748
/** Login form group. */
4849
loginForm: FormGroup;
@@ -126,7 +127,7 @@ export class LoginFormComponent implements OnInit {
126127
'',
127128
[
128129
Validators.required,
129-
Validators.minLength(8)
130+
Validators.minLength(environment.minPasswordLength)
130131
]
131132
],
132133
remember: false
@@ -144,9 +145,12 @@ export class LoginFormComponent implements OnInit {
144145
const control = this.loginForm.get(controlName);
145146
if (control?.hasError('required')) {
146147
return 'This field is required';
147-
} else if (control?.hasError('minlength')) {
148-
return `Minimum length is ${control.errors?.minlength.requiredLength}`;
149148
}
149+
if (control?.hasError('minlength')) {
150+
const requiredLength = control.errors?.['minlength']?.requiredLength;
151+
return `Minimum length is ${requiredLength}`;
152+
}
153+
150154
return '';
151155
}
152156
}

src/assets/env.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@
112112
window['env']['externalNationalIdSystemApiKey'] = '';
113113
window['env']['externalNationalIdRegex'] = '';
114114

115+
// Password Configuration
116+
window['env']['minPasswordLength'] = 8;
117+
115118
// OIDC Plugin Environment variables
116119
window['env']['oidcServerEnabled'] = false;
117120
window['env']['oidcBaseUrl'] = '';

src/assets/env.template.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@
9191
// Min Password length
9292
window['env']['minPasswordLength'] = '$MIFOS_MIN_PASSWORD_LENGTH';
9393

94+
// Password Regex
95+
window['env']['minPasswordLength'] = '$MIFOS_MIN_PASSWORD_LENGTH';
96+
9497
// Enable or Disable HTTP Cache
9598
window['env']['httpCacheEnabled'] = '$MIFOS_HTTP_CACHE_ENABLED';
9699

src/assets/translations/cs-CS.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"Buy Down Fee Adjustment amount must be lower or equal to": "Výše úpravy poplatku za odkoupení musí být nižší nebo rovna",
1717
"Email not valid": "Email není platný",
1818
"Filling Details": "Kliknutím začněte vyplňovat podrobnosti. * pole označení jsou nezbytná. Pro více podrobností klikněte na:",
19-
"Password is required": "Je vyžadováno heslo",
19+
"Password is required": "Je vyžadováno heslo (minimální délka {{min}} znaků)",
2020
"Searched query resulted more than 200 records": "Výsledkem hledaného dotazu bylo více než 200 záznamů, přičemž prvních 200 záznamů bylo zobrazeno.",
2121
"Username is required": "Uživatelské jméno je povinné",
2222
"Username or password incorrect.": "Nesprávné uživatelské jméno nebo heslo",

src/assets/translations/de-DE.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"Buy Down Fee Adjustment amount must be lower or equal to": "Der Anpassungsbetrag der Ankaufsgebühr muss niedriger oder gleich sein als",
1717
"Email not valid": "E-Mail ungültig",
1818
"Filling Details": "Klicken Sie hier, um mit dem Ausfüllen der Details zu beginnen. * Markierungsfelder sind erforderlich. Für weitere Details klicken Sie:",
19-
"Password is required": "Passwort wird benötigt",
19+
"Password is required": "Passwort wird benötigt (Mindestlänge {{min}} Zeichen)",
2020
"Searched query resulted more than 200 records": "Die Suchanfrage ergab mehr als 200 Datensätze, wobei die ersten 200 Datensätze angezeigt wurden.",
2121
"Username is required": "Benutzername wird benötigt",
2222
"Username or password incorrect.": "Benutzername oder Passwort falsch",

src/assets/translations/en-US.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@
907907
"is": "is",
908908
"Is": "is",
909909
"is required": "is required",
910-
"pass is required": "is required(min length 12)",
910+
"pass is required": "is required (min length {{min}})",
911911
"least one uppercase": "least one uppercase",
912912
"lowercase and special character": "lowercase and special character",
913913
"must be": "must be",

src/assets/translations/es-CL.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"Buy Down Fee Adjustment amount must be lower or equal to": "El importe del ajuste de la cuota de readquisición debe ser igual o inferior a",
1717
"Email not valid": "Correo electrónico no válido",
1818
"Filling Details": "Haga clic para comenzar a completar los detalles. * Los campos de marca son necesarios. Para más detalles haga clic en:",
19-
"Password is required": "se requiere contraseña",
19+
"Password is required": "se requiere contraseña (longitud mínima {{min}})",
2020
"Searched query resulted more than 200 records": "La consulta buscada resultó en más de 200 registros, mostrando los primeros 200 registros.",
2121
"Username is required": "Se requiere nombre de usuario",
2222
"Username or password incorrect.": "Usuario o contraseña incorrectos",

src/assets/translations/es-MX.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"Buy Down Fee Adjustment amount must be lower or equal to": "El importe del ajuste de la cuota de readquisición debe ser igual o inferior a",
1717
"Email not valid": "Correo electrónico no válido",
1818
"Filling Details": "Haga clic para comenzar a completar los detalles. * Los campos de marca son necesarios. Para más detalles haga clic en:",
19-
"Password is required": "se requiere contraseña",
19+
"Password is required": "se requiere contraseña (longitud mínima {{min}})",
2020
"Searched query resulted more than 200 records": "La consulta buscada resultó en más de 200 registros, mostrando los primeros 200 registros.",
2121
"Username is required": "Se requiere nombre de usuario",
2222
"Username or password incorrect.": "Usuario o contraseña incorrectos",

0 commit comments

Comments
 (0)