Update ChangePassword.razor (#1404)

This commit is contained in:
Leendert de Borst
2026-01-17 10:32:35 +01:00
parent 4ff3e614e9
commit 08b6920682
@@ -180,7 +180,10 @@ else
CurrentSalt,
srpIdentity);
// Generate salt and verifier for new password using Rust WASM.
// Generate salt for new password using Rust WASM.
// IMPORTANT: We must use the same salt for both key derivation AND SRP verifier generation.
// Otherwise login will fail because the server returns this salt, but the password hash
// was derived with a different salt.
var newSalt = await SrpService.GenerateSaltAsync();
byte[] newPasswordHash = await Encryption.DeriveKeyFromPasswordAsync(PasswordChangeFormModel.NewPassword, newSalt);
@@ -193,8 +196,9 @@ else
// it is encrypted with the new password hash.
await AuthService.StoreEncryptionKeyAsync(newPasswordHash);
// Use srpIdentity for generating the new verifier to maintain consistency.
var (srpSalt, srpVerifier) = await SrpService.PreparePasswordChangeAsync(srpIdentity, newPasswordHashString);
// Derive the SRP verifier using the same salt that was used for key derivation.
var newPrivateKey = await SrpService.DerivePrivateKeyAsync(newSalt, srpIdentity, newPasswordHashString);
var newVerifier = await SrpService.DeriveVerifierAsync(newPrivateKey);
// Prepare new vault model to update to.
var encryptedBase64String = await DbService.GetEncryptedDatabaseBase64String();
@@ -216,8 +220,8 @@ else
UpdatedAt = vault.UpdatedAt,
CurrentClientPublicEphemeral = ClientEphemeral.Public,
CurrentClientSessionProof = ClientSession.Proof,
NewPasswordSalt = srpSalt,
NewPasswordVerifier = srpVerifier
NewPasswordSalt = newSalt,
NewPasswordVerifier = newVerifier
};
// Clear form.