public void GetSalt_ReturnsUniqueSaltPerInstance() { var passwordOne = new Password(ClearTextPassword); var passwordTwo = new Password(ClearTextPassword); Assert.AreNotEqual(passwordOne.GetSalt(), passwordTwo.GetSalt()); }
public void GetHashed_SamePasswordDifferentSalt_ReturnsDifferentHashedPassword() { var hashedPasswordOne = new Password(ClearTextPassword, Salt).GetHashed(); var hashedPasswordTwo = new Password(ClearTextPassword, Salt + "2").GetHashed(); Assert.AreNotEqual(hashedPasswordOne, hashedPasswordTwo); }
public void GetSalt_ReturnsUsedSalt() { var password = new Password(ClearTextPassword, Salt); string actualSalt = password.GetSalt(); Assert.AreEqual(Salt, actualSalt); }
public void SetPassword() { var userRepository = new UserRepository(); var userEntity = userRepository.GetBy(Id); var password = new Password(ConfirmedPassword); userEntity.HashedPassword = password.GetHashed(); userEntity.Salt = password.GetSalt(); userRepository.SaveChanges(); }
public bool Authenthicate() { var userEntity = repository.GetBy(Email); if (userEntity == null || !userEntity.IsConfirmed) { return false; } FromEntity(userEntity); var password = new Password(Password, userEntity.Salt); return userEntity.HashedPassword == password.GetHashed(); }
private UserEntity ToUserEntity() { var password = new Password(Password); var userEntity = new UserEntity { Name = Name, Email = Email, IsConfirmed = false, Id = Id, Salt = password.GetSalt(), HashedPassword = password.GetHashed(), }; userEntity.Roles.Add(new RoleRepository().GetRole(Role.Regular)); return userEntity; }
public void GetHashed_IsDifferentThanClearPassword() { var password = new Password(ClearTextPassword, "salt"); Assert.AreNotEqual(ClearTextPassword, password.GetHashed()); }