From 254cad29b37c8c7ae79b5386317fa74792b7c1ca Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 7 Apr 2025 10:39:26 -0400 Subject: [PATCH] [PM-8951] set pin validation to min length of 4 (#13312) * set pin validation to min length of 4 * use reactive forms * PM-8951 - SetPin - remove dialog close logic if pin is invalid so validation errors can be shown to the user. --------- Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com> Co-authored-by: Jared Snider --- .../src/auth/components/set-pin.component.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libs/angular/src/auth/components/set-pin.component.ts b/libs/angular/src/auth/components/set-pin.component.ts index 9f63e5e923f..d2fceb34bb9 100644 --- a/libs/angular/src/auth/components/set-pin.component.ts +++ b/libs/angular/src/auth/components/set-pin.component.ts @@ -16,7 +16,7 @@ export class SetPinComponent implements OnInit { showMasterPasswordOnClientRestartOption = true; setPinForm = this.formBuilder.group({ - pin: ["", [Validators.required]], + pin: ["", [Validators.required, Validators.minLength(4)]], requireMasterPasswordOnClientRestart: true, }); @@ -37,24 +37,26 @@ export class SetPinComponent implements OnInit { } submit = async () => { - const pin = this.setPinForm.get("pin").value; + const pinFormControl = this.setPinForm.controls.pin; const requireMasterPasswordOnClientRestart = this.setPinForm.get( "requireMasterPasswordOnClientRestart", ).value; - if (Utils.isNullOrWhitespace(pin)) { - this.dialogRef.close(false); + if (Utils.isNullOrWhitespace(pinFormControl.value) || pinFormControl.invalid) { return; } const userId = (await firstValueFrom(this.accountService.activeAccount$))?.id; const userKey = await this.keyService.getUserKey(); - const userKeyEncryptedPin = await this.pinService.createUserKeyEncryptedPin(pin, userKey); + const userKeyEncryptedPin = await this.pinService.createUserKeyEncryptedPin( + pinFormControl.value, + userKey, + ); await this.pinService.setUserKeyEncryptedPin(userKeyEncryptedPin, userId); const pinKeyEncryptedUserKey = await this.pinService.createPinKeyEncryptedUserKey( - pin, + pinFormControl.value, userKey, userId, );