Skip to content
Snippets Groups Projects
Commit a8636b0e authored by Kristof De Langhe's avatar Kristof De Langhe
Browse files

69432: Fix being able to send invalid password form + 6 character password validator

parent 33e395a7
Branches
No related merge requests found
......@@ -1449,6 +1449,8 @@
"profile.security.form.error.matching-passwords": "The passwords do not match.",
"profile.security.form.error.password-length": "The password should be at least 6 characters long.",
"profile.security.form.info": "Optionally, you can enter a new password in the box below, and confirm it by typing it again into the second box. It should be at least six characters long.",
"profile.security.form.label.password": "Password",
......@@ -1461,6 +1463,8 @@
"profile.security.form.notifications.error.title": "Error changing passwords",
"profile.security.form.notifications.error.not-long-enough": "The password has to be at least 6 characters long.",
"profile.security.form.notifications.error.not-same": "The provided passwords are not the same.",
"profile.title": "Update Profile",
......
......@@ -5,4 +5,5 @@
[formGroup]="formGroup"
[displaySubmit]="false">
</ds-form>
<div class="container-fluid text-danger" *ngIf="formGroup.hasError('notLongEnough')">{{'profile.security.form.error.password-length' | translate}}</div>
<div class="container-fluid text-danger" *ngIf="formGroup.hasError('notSame')">{{'profile.security.form.error.matching-passwords' | translate}}</div>
......@@ -80,14 +80,14 @@ describe('ProfilePageSecurityFormComponent', () => {
});
});
describe('when both password fields are filled in and equal', () => {
describe('when both password fields are filled in, long enough and equal', () => {
let result;
let operations;
beforeEach(() => {
setModelValue('password', 'test');
setModelValue('passwordrepeat', 'test');
operations = [{ op: 'replace', path: '/password', value: 'test' }];
setModelValue('password', 'testest');
setModelValue('passwordrepeat', 'testest');
operations = [{ op: 'replace', path: '/password', value: 'testest' }];
result = component.updateSecurity();
});
......
......@@ -64,7 +64,7 @@ export class ProfilePageSecurityFormComponent implements OnInit {
}
ngOnInit(): void {
this.formGroup = this.formService.createFormGroup(this.formModel, { validators: this.checkPasswords });
this.formGroup = this.formService.createFormGroup(this.formModel, { validators: [this.checkPasswordsEqual, this.checkPasswordLength] });
this.updateFieldTranslations();
this.translate.onLangChange
.subscribe(() => {
......@@ -87,11 +87,21 @@ export class ProfilePageSecurityFormComponent implements OnInit {
* Check if both password fields are filled in and equal
* @param group The FormGroup to validate
*/
checkPasswords(group: FormGroup) {
checkPasswordsEqual(group: FormGroup) {
const pass = group.get('password').value;
const repeatPass = group.get('passwordrepeat').value;
return isEmpty(repeatPass) || pass === repeatPass ? null : { notSame: true };
return pass === repeatPass ? null : { notSame: true };
}
/**
* Check if the password is at least 6 characters long
* @param group The FormGroup to validate
*/
checkPasswordLength(group: FormGroup) {
const pass = group.get('password').value;
return isEmpty(pass) || pass.length >= 6 ? null : { notLongEnough: true };
}
/**
......@@ -109,7 +119,12 @@ export class ProfilePageSecurityFormComponent implements OnInit {
const passEntered = isNotEmpty(pass);
if (!this.formGroup.valid) {
if (passEntered) {
this.notificationsService.error(this.translate.instant(this.NOTIFICATIONS_PREFIX + 'error.not-same'));
if (this.checkPasswordsEqual(this.formGroup) != null) {
this.notificationsService.error(this.translate.instant(this.NOTIFICATIONS_PREFIX + 'error.not-same'));
}
if (this.checkPasswordLength(this.formGroup) != null) {
this.notificationsService.error(this.translate.instant(this.NOTIFICATIONS_PREFIX + 'error.not-long-enough'));
}
return true;
}
return false;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment