public async Task<TwoFactorResponseModel> PutTwoFactorRegenerate([FromBody]RegenerateTwoFactorRequestModel model) { var user = _currentContext.User; if(!await _userManager.CheckPasswordAsync(user, model.MasterPasswordHash)) { await Task.Delay(2000); throw new BadRequestException("MasterPasswordHash", "Invalid password."); } if(!await _userManager.VerifyTwoFactorTokenAsync(user, "Authenticator", model.Token)) { await Task.Delay(2000); throw new BadRequestException("Token", "Invalid token."); } if(user.TwoFactorEnabled) { user.TwoFactorRecoveryCode = Guid.NewGuid().ToString("N"); await _userService.SaveUserAsync(user); } var response = new TwoFactorResponseModel(user); return response; }
public async Task<TwoFactorResponseModel> GetTwoFactor(string masterPasswordHash, TwoFactorProvider provider) { var user = _currentContext.User; if(!await _userManager.CheckPasswordAsync(user, masterPasswordHash)) { await Task.Delay(2000); throw new BadRequestException("MasterPasswordHash", "Invalid password."); } await _userService.GetTwoFactorAsync(user, provider); var response = new TwoFactorResponseModel(user); return response; }