public void ComparePasswords_NoMatch(string storedPassword, string enteredPassword) { //arrange var hashedStoredPassword = _passwordHelper.GenerateSecurePassword(Encoding.ASCII.GetBytes(storedPassword)); //act var result = _passwordHelper.CompareSecurePasswords(Encoding.ASCII.GetBytes(enteredPassword), hashedStoredPassword); //assert Assert.False(result, $"Was expecting passwords to not match, but they matched. Stored password: {storedPassword}. Entered password: {enteredPassword}"); }
public UserReturnModel UpdateUserInfo(Guid apiTokenGuid, string password, UserUpdateModel userUpdateModel) { var user = _userManager.GetUserByApiToken(apiTokenGuid); if (user == null) { throw new UserNotFoundException($"User could not be found where API token is {apiTokenGuid}"); } if (!_passwordHelper.CompareSecurePasswords(Encoding.ASCII.GetBytes(password), user.Password)) { throw new UnauthorizedAccessException("Password entered was incorrect"); } user.FirstName = userUpdateModel.FirstName; user.LastName = userUpdateModel.LastName; user.Email = userUpdateModel.EmailAddress; HandleUserSettings(user, (byte)StaticData.WordType.RacialSlur, userUpdateModel.Racism); HandleUserSettings(user, (byte)StaticData.WordType.Sexism, userUpdateModel.Sexism); HandleUserSettings(user, (byte)StaticData.WordType.Vulgarity, userUpdateModel.Vulgarity); user.CallsPerMonth = _accountTypeHelper.GetCallsPerMonth(userUpdateModel.PricingTierId); user.PricePerMonth = _accountTypeHelper.GetPricePerMonth(userUpdateModel.PricingTierId); _userManager.UpdateExistingUser(user); return(MapUserToModel(user)); }
public UserReturnModel Signin(string email, string password) { var user = _userManager.GetUserByEmail(email); if (user == null) { throw new UserNotFoundException($"Could not find user where email address is {email}"); } if (_passwordHelper.CompareSecurePasswords(Encoding.ASCII.GetBytes(password), user.Password)) { _userManager.CheckUnlockAccount(user); return(_webPageHelper.MapUserToModel(user)); } throw new UnauthorizedAccessException("Password entered was incorrect"); }