public async Task <bool> VerifyOneTimePassword(User user, OnePasswordType kind, string code) { Generator = NewGenerator(user); // TODO: Stop Storing One Time Passwords, maybe just count them? OneTimePassword password = user.OneTimePasswords. FirstOrDefault(p => p.IsActive && p.Kind == kind); if (password == null) { return(false); } if (!Generator.VerifyHotp(code, user.OneTimePasswords.LongCount())) { return(false); } return(await Task.FromResult(password.Code == code)); }
public async Task <bool> ValidateOneTimePassword(User user, OnePasswordType kind, string code) { Generator = NewGenerator(user); // TODO: Stop Storing One Time Passwords, maybe just count them? OneTimePassword password = user.OneTimePasswords. FirstOrDefault(p => p.IsActive && p.Kind == kind); if (password == null) { return(false); } if (!Generator.VerifyHotp(code, user.OneTimePasswords.LongCount())) { return(false); } if (!password.Validate(code)) { return(false); } switch (kind) { // TODO: Deprecate OnePasswordType case OnePasswordType.Email: user.EmailConfirmed = true; break; case OnePasswordType.Phone: user.PhoneNumberConfirmed = true; break; } await DataStore.UpdateOneAsync(user); return(true); }
public async Task <OneTimePassword> GenerateOneTimePassword(User user, OnePasswordType kind) { Generator = NewGenerator(user); OneTimePassword password = user.OneTimePasswords .FirstOrDefault(p => p.IsActive && p.Kind == kind); if (password != null) { return(password); } password = new OneTimePassword() { Kind = kind }; user.OneTimePasswords.Add(password); password.Code = Generator.ComputeHOTP(user.OneTimePasswords.LongCount()); await DataStore.UpdateOneAsync(user); return(password); }