diff --git a/src/Core/KeyManagement/UserKey/Implementations/RotateUserAccountKeysCommand.cs b/src/Core/KeyManagement/UserKey/Implementations/RotateUserAccountKeysCommand.cs index 742c92aeae36..b74e0346b33d 100644 --- a/src/Core/KeyManagement/UserKey/Implementations/RotateUserAccountKeysCommand.cs +++ b/src/Core/KeyManagement/UserKey/Implementations/RotateUserAccountKeysCommand.cs @@ -93,6 +93,7 @@ public async Task PasswordChangeAndRotateUserAccountKeysAsync(Us user.Key = model.MasterPasswordUnlockData.MasterKeyWrappedUserKey; user.MasterPassword = _passwordHasher.HashPassword(user, model.MasterPasswordAuthenticationData.MasterPasswordAuthenticationHash); user.MasterPasswordHint = model.MasterPasswordHint; + user.LastPasswordChangeDate = DateTime.UtcNow; await _userRepository.UpdateUserKeyAndEncryptedDataV2Async(user, saveEncryptedDataActions); diff --git a/src/Infrastructure.EntityFramework/Repositories/UserRepository.cs b/src/Infrastructure.EntityFramework/Repositories/UserRepository.cs index dab556e72f0c..982dcc3f165d 100644 --- a/src/Infrastructure.EntityFramework/Repositories/UserRepository.cs +++ b/src/Infrastructure.EntityFramework/Repositories/UserRepository.cs @@ -249,6 +249,7 @@ public async Task UpdateUserKeyAndEncryptedDataV2Async(Core.Entities.User user, userEntity.MasterPassword = user.MasterPassword; userEntity.MasterPasswordHint = user.MasterPasswordHint; + userEntity.LastPasswordChangeDate = user.LastPasswordChangeDate; userEntity.LastKeyRotationDate = user.LastKeyRotationDate; userEntity.AccountRevisionDate = user.AccountRevisionDate; diff --git a/test/Core.Test/KeyManagement/UserKey/RotateUserAccountKeysCommandTests.cs b/test/Core.Test/KeyManagement/UserKey/RotateUserAccountKeysCommandTests.cs index 46acfe9e3795..629496ed50d5 100644 --- a/test/Core.Test/KeyManagement/UserKey/RotateUserAccountKeysCommandTests.cs +++ b/test/Core.Test/KeyManagement/UserKey/RotateUserAccountKeysCommandTests.cs @@ -127,12 +127,21 @@ public async Task PasswordChangeAndRotateUserAccountKeysAsync_V1_Success(SutProv var signatureRepository = sutProvider.GetDependency(); SetV1ExistingUser(user, signatureRepository); SetV1ModelUser(model.BaseData); + user.LastPasswordChangeDate = DateTime.UtcNow.AddDays(-1); + user.LastKeyRotationDate = DateTime.UtcNow.AddDays(-1); sutProvider.GetDependency().CheckPasswordAsync(user, model.OldMasterKeyAuthenticationHash) .Returns(true); + var before = DateTime.UtcNow; var result = await sutProvider.Sut.PasswordChangeAndRotateUserAccountKeysAsync(user, model); + var after = DateTime.UtcNow; + Assert.Equal(IdentityResult.Success, result); + Assert.NotNull(user.LastPasswordChangeDate); + Assert.InRange(user.LastPasswordChangeDate.Value, before, after); + Assert.NotNull(user.LastKeyRotationDate); + Assert.InRange(user.LastKeyRotationDate.Value, before, after); } [Theory, BitAutoData] @@ -147,9 +156,16 @@ public async Task PasswordChangeAndRotateUserAccountKeysAsync_UpgradeV1ToV2_Succ sutProvider.GetDependency().CheckPasswordAsync(user, model.OldMasterKeyAuthenticationHash) .Returns(true); + var before = DateTime.UtcNow; var result = await sutProvider.Sut.PasswordChangeAndRotateUserAccountKeysAsync(user, model); + var after = DateTime.UtcNow; + Assert.Equal(IdentityResult.Success, result); Assert.Equal(user.SecurityState, model.BaseData.AccountKeys.SecurityStateData!.SecurityState); + Assert.NotNull(user.LastPasswordChangeDate); + Assert.InRange(user.LastPasswordChangeDate.Value, before, after); + Assert.NotNull(user.LastKeyRotationDate); + Assert.InRange(user.LastKeyRotationDate.Value, before, after); }