public void CheckPassWithHash_IfPasswordAndPasswordHash_ReturnsTrue() { var hash = _passHasher.HashPassword(password); var isMatch = _passHasher.CheckPassWithHash(password, hash); Assert.True(isMatch); }
public async Task <TokenDTO> SignInAsync(LoginViewModel loginModel) { var existedUser = await _unitOfWork.AuthRepository.SingleOrDefaultAsync(u => u.Email == loginModel.Email); if (existedUser == null) { return(null); } if (!_hasher.CheckPassWithHash(loginModel.Password, existedUser.Password)) { return(null); } if (existedUser.IsEmailConfirmed == false) { throw new ApiException(HttpStatusCode.Forbidden, "Email must be confirmed before signing in."); } var token = await GenerateNewTokensAsync(existedUser); var refreshToken = SetUpRefreshToken(existedUser, token.RefreshToken); await _jwtManager.UpdateAsync(existedUser.Id, refreshToken); return(token); }
public async Task ChangePasswordAsync(NewPasswordViewModel model) { var user = await _unitOfWork.UserRepository.GetAsync(model.UserId); if (user == null) { throw new ApiException(HttpStatusCode.NotFound, "User was not found"); } if (!_hasher.CheckPassWithHash(model.OldPassword, user.Password)) { throw new ApiException(HttpStatusCode.BadRequest, "Old password incorrect"); } user.Password = _hasher.HashPassword(model.Password); await _unitOfWork.Complete(); }