1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-27 18:13:29 +00:00
Files
browser/libs/vault/src/components/password-reprompt.component.ts
Bernd Schoolmann cf7f9cfc7e [BEEEP|PM-32521] Remove compare key hash and move to proof of decryption (#19101)
* Remove compare key hash and move to proof of decryption

* Fix cli build

* Fix mv2

* Fix provider

* Prettier
2026-02-25 17:02:04 +01:00

85 lines
2.8 KiB
TypeScript

import { Component } from "@angular/core";
import { FormBuilder, ReactiveFormsModule, Validators } from "@angular/forms";
import { firstValueFrom } from "rxjs";
import { JslibModule } from "@bitwarden/angular/jslib.module";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { getUserId } from "@bitwarden/common/auth/services/account.service";
import { MasterPasswordUnlockService } from "@bitwarden/common/key-management/master-password/abstractions/master-password-unlock.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import {
DialogRef,
AsyncActionsModule,
ButtonModule,
DialogModule,
FormFieldModule,
IconButtonModule,
ToastService,
} from "@bitwarden/components";
/**
* Used to verify the user's Master Password for the "Master Password Re-prompt" feature only.
* See UserVerificationComponent for any other situation where you need to verify the user's identity.
*/
// FIXME(https://bitwarden.atlassian.net/browse/CL-764): Migrate to OnPush
// eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection
@Component({
selector: "vault-password-reprompt",
imports: [
JslibModule,
AsyncActionsModule,
ButtonModule,
DialogModule,
FormFieldModule,
IconButtonModule,
ReactiveFormsModule,
],
templateUrl: "password-reprompt.component.html",
})
export class PasswordRepromptComponent {
formGroup = this.formBuilder.group({
masterPassword: ["", { validators: [Validators.required], updateOn: "submit" }],
});
constructor(
protected masterPasswordUnlockService: MasterPasswordUnlockService,
protected platformUtilsService: PlatformUtilsService,
protected i18nService: I18nService,
protected formBuilder: FormBuilder,
protected dialogRef: DialogRef,
private toastService: ToastService,
protected accountService: AccountService,
) {}
submit = async () => {
// Exit early when a master password is not provided.
// The form field required error will be shown to users in these cases.
if (!this.formGroup.value.masterPassword) {
return;
}
const userId = await firstValueFrom(getUserId(this.accountService.activeAccount$));
if (userId == null) {
throw new Error("An active user is expected while doing password reprompt.");
}
if (
!(await this.masterPasswordUnlockService.proofOfDecryption(
this.formGroup.value.masterPassword,
userId,
))
) {
this.toastService.showToast({
variant: "error",
title: this.i18nService.t("errorOccurred"),
message: this.i18nService.t("invalidMasterPassword"),
});
return;
}
this.dialogRef.close(true);
};
}