mirror of
https://github.com/bitwarden/browser
synced 2026-02-09 05:00:10 +00:00
simplify changePassword(...) parameters
This commit is contained in:
@@ -93,7 +93,7 @@ export class ChangePasswordComponent implements OnInit {
|
||||
await this.syncService.fullSync(true);
|
||||
|
||||
if (this.activeAccount == null) {
|
||||
throw new Error("User or userId not found");
|
||||
throw new Error("User not found");
|
||||
}
|
||||
|
||||
await this.changePasswordService.rotateUserKeyMasterPasswordAndEncryptedData(
|
||||
@@ -103,14 +103,7 @@ export class ChangePasswordComponent implements OnInit {
|
||||
passwordInputResult.newPasswordHint,
|
||||
);
|
||||
} else {
|
||||
await this.changePasswordService.changePassword(
|
||||
passwordInputResult.currentMasterKey,
|
||||
passwordInputResult.currentServerMasterKeyHash,
|
||||
passwordInputResult.newPasswordHint,
|
||||
passwordInputResult.newMasterKey,
|
||||
passwordInputResult.newServerMasterKeyHash,
|
||||
this.userId,
|
||||
);
|
||||
await this.changePasswordService.changePassword(passwordInputResult, this.userId);
|
||||
|
||||
this.toastService.showToast({
|
||||
variant: "success",
|
||||
@@ -153,8 +146,8 @@ export class ChangePasswordComponent implements OnInit {
|
||||
|
||||
const request = new PasswordRequest();
|
||||
request.masterPasswordHash = passwordInputResult.currentServerMasterKeyHash;
|
||||
request.masterPasswordHint = passwordInputResult.newPasswordHint;
|
||||
request.newMasterPasswordHash = passwordInputResult.newServerMasterKeyHash;
|
||||
request.masterPasswordHint = passwordInputResult.newPasswordHint;
|
||||
request.key = newMasterKeyEncryptedUserKey[1].encryptedString as string;
|
||||
|
||||
try {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { PasswordInputResult } from "@bitwarden/auth/angular";
|
||||
import { Account } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { UserId } from "@bitwarden/common/types/guid";
|
||||
import { MasterKey } from "@bitwarden/common/types/key";
|
||||
|
||||
export abstract class ChangePasswordService {
|
||||
abstract rotateUserKeyMasterPasswordAndEncryptedData(
|
||||
@@ -15,12 +15,5 @@ export abstract class ChangePasswordService {
|
||||
user: Account,
|
||||
): Promise<void | null>;
|
||||
|
||||
abstract changePassword(
|
||||
currentMasterKey: MasterKey,
|
||||
currentServerMasterKeyHash: string,
|
||||
newPasswordHint: string,
|
||||
newMasterKey: MasterKey,
|
||||
newServerMasterKeyHash: string,
|
||||
userId: UserId,
|
||||
): Promise<void>;
|
||||
abstract changePassword(passwordInputResult: PasswordInputResult, userId: UserId): Promise<void>;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { PasswordInputResult } from "@bitwarden/auth/angular";
|
||||
import { Account } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { MasterPasswordApiService } from "@bitwarden/common/auth/abstractions/master-password-api.service.abstraction";
|
||||
import { PasswordRequest } from "@bitwarden/common/auth/models/request/password.request";
|
||||
import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/key-management/master-password/abstractions/master-password.service.abstraction";
|
||||
import { UserId } from "@bitwarden/common/types/guid";
|
||||
import { MasterKey } from "@bitwarden/common/types/key";
|
||||
import { KeyService } from "@bitwarden/key-management";
|
||||
|
||||
import { ChangePasswordService } from "../../abstractions";
|
||||
@@ -31,20 +31,13 @@ export class DefaultChangePasswordService implements ChangePasswordService {
|
||||
return null; // implemented in Web
|
||||
}
|
||||
|
||||
async changePassword(
|
||||
currentMasterKey: MasterKey,
|
||||
currentServerMasterKeyHash: string,
|
||||
newPasswordHint: string,
|
||||
newMasterKey: MasterKey,
|
||||
newServerMasterKeyHash: string,
|
||||
userId: UserId,
|
||||
) {
|
||||
async changePassword(passwordInputResult: PasswordInputResult, userId: UserId) {
|
||||
if (!userId) {
|
||||
throw new Error("The change password process requires a userId");
|
||||
}
|
||||
|
||||
const decryptedUserKey = await this.masterPasswordService.decryptUserKeyWithMasterKey(
|
||||
currentMasterKey,
|
||||
passwordInputResult.currentMasterKey,
|
||||
userId,
|
||||
);
|
||||
|
||||
@@ -53,14 +46,14 @@ export class DefaultChangePasswordService implements ChangePasswordService {
|
||||
}
|
||||
|
||||
const newMasterKeyEncryptedUserKey = await this.keyService.encryptUserKeyWithMasterKey(
|
||||
newMasterKey,
|
||||
passwordInputResult.newMasterKey,
|
||||
decryptedUserKey,
|
||||
);
|
||||
|
||||
const request = new PasswordRequest();
|
||||
request.masterPasswordHash = currentServerMasterKeyHash;
|
||||
request.masterPasswordHint = newPasswordHint;
|
||||
request.newMasterPasswordHash = newServerMasterKeyHash;
|
||||
request.masterPasswordHash = passwordInputResult.currentServerMasterKeyHash;
|
||||
request.newMasterPasswordHash = passwordInputResult.newServerMasterKeyHash;
|
||||
request.masterPasswordHint = passwordInputResult.newPasswordHint;
|
||||
request.key = newMasterKeyEncryptedUserKey[1].encryptedString as string;
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user