mirror of
https://github.com/bitwarden/browser
synced 2025-12-11 22:03:36 +00:00
[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 <jsnider@bitwarden.com>
This commit is contained in:
@@ -16,7 +16,7 @@ export class SetPinComponent implements OnInit {
|
|||||||
showMasterPasswordOnClientRestartOption = true;
|
showMasterPasswordOnClientRestartOption = true;
|
||||||
|
|
||||||
setPinForm = this.formBuilder.group({
|
setPinForm = this.formBuilder.group({
|
||||||
pin: ["", [Validators.required]],
|
pin: ["", [Validators.required, Validators.minLength(4)]],
|
||||||
requireMasterPasswordOnClientRestart: true,
|
requireMasterPasswordOnClientRestart: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -37,24 +37,26 @@ export class SetPinComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
submit = async () => {
|
submit = async () => {
|
||||||
const pin = this.setPinForm.get("pin").value;
|
const pinFormControl = this.setPinForm.controls.pin;
|
||||||
const requireMasterPasswordOnClientRestart = this.setPinForm.get(
|
const requireMasterPasswordOnClientRestart = this.setPinForm.get(
|
||||||
"requireMasterPasswordOnClientRestart",
|
"requireMasterPasswordOnClientRestart",
|
||||||
).value;
|
).value;
|
||||||
|
|
||||||
if (Utils.isNullOrWhitespace(pin)) {
|
if (Utils.isNullOrWhitespace(pinFormControl.value) || pinFormControl.invalid) {
|
||||||
this.dialogRef.close(false);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const userId = (await firstValueFrom(this.accountService.activeAccount$))?.id;
|
const userId = (await firstValueFrom(this.accountService.activeAccount$))?.id;
|
||||||
const userKey = await this.keyService.getUserKey();
|
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);
|
await this.pinService.setUserKeyEncryptedPin(userKeyEncryptedPin, userId);
|
||||||
|
|
||||||
const pinKeyEncryptedUserKey = await this.pinService.createPinKeyEncryptedUserKey(
|
const pinKeyEncryptedUserKey = await this.pinService.createPinKeyEncryptedUserKey(
|
||||||
pin,
|
pinFormControl.value,
|
||||||
userKey,
|
userKey,
|
||||||
userId,
|
userId,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user