-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathSetInitialMasterPasswordQuery.cs
More file actions
40 lines (33 loc) · 1.45 KB
/
SetInitialMasterPasswordQuery.cs
File metadata and controls
40 lines (33 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using Bit.Core.Entities;
using Bit.Core.KeyManagement.MasterPassword.Interfaces;
using Bit.Core.KeyManagement.Models.Data;
using Microsoft.AspNetCore.Identity;
namespace Bit.Core.KeyManagement.MasterPassword;
/// <inheritdoc />
public class SetInitialMasterPasswordQuery : ISetInitialMasterPasswordQuery
{
private readonly IPasswordHasher<User> _passwordHasher;
public SetInitialMasterPasswordQuery(IPasswordHasher<User> passwordHasher)
{
_passwordHasher = passwordHasher;
}
/// <inheritdoc />
public Task RunAsync(User user, SetInitialMasterPasswordData data)
{
data.ValidateForUser(user);
user.MasterPassword = _passwordHasher.HashPassword(user,
data.MasterPasswordAuthentication.MasterPasswordAuthenticationHash);
user.MasterPasswordHint = data.MasterPasswordHint;
user.MasterPasswordSalt = data.MasterPasswordAuthentication.Salt;
user.Key = data.MasterPasswordUnlock.MasterKeyWrappedUserKey;
user.Kdf = data.MasterPasswordAuthentication.Kdf.KdfType;
user.KdfIterations = data.MasterPasswordAuthentication.Kdf.Iterations;
user.KdfMemory = data.MasterPasswordAuthentication.Kdf.Memory;
user.KdfParallelism = data.MasterPasswordAuthentication.Kdf.Parallelism;
var now = DateTime.UtcNow;
user.RevisionDate = now;
user.AccountRevisionDate = now;
user.LastPasswordChangeDate = now;
return Task.CompletedTask;
}
}