public void CreateHashedPassword_Length_Always_48(string password) { var hasher = new PasswordHasher(); var hashedPassword = hasher.CreateHashedPassword(password); Assert.Equal(48, hashedPassword.Length); }
public bool SignUp(SignUpRequestDto signUpRequest) { var user = _repository.Get <AppUser>(x => x.Username == signUpRequest.Username || x.Email == signUpRequest.Email); if (user == null) { string salt = PasswordHasher.CreateSalt(); string hash = PasswordHasher.CreateHashedPassword(signUpRequest.Password, salt); _repository.Insert <AppUser>( new AppUser { Email = signUpRequest.Email, Username = signUpRequest.Username, Salt = salt, Password = hash }); _repository.SaveChanges(); return(true); } else { return(false); } }
public async Task UpdatePassword(Student student, string password) { PasswordHasher <Student, Guid> .CreateHashedPassword(password, out var hashedPass, out var saltPass); student.HashedPassword = hashedPass; student.SaltPassword = saltPass; await UpdateAsync(student); }
public async Task UpdatePassword(Employer entity, string password) { PasswordHasher <Employer, Guid> .CreateHashedPassword(password, out byte[] hashedPass, out byte[] saltPass); entity.HashedPassword = hashedPass; entity.SaltPassword = saltPass; await UpdateAsync(entity); }
public void CreateHashedPassword_IsSamePassword() { var hasher = new PasswordHasher(); var password = "******"; var hashedPassword = hasher.CreateHashedPassword(password); Assert.True(hasher.IsSamePassword(password, hashedPassword)); }
public void Hashed_Password_Matches() { var pw = "thisispassword123"; var salt = PasswordHasher.CreateSalt(); var hash = PasswordHasher.CreateHashedPassword(pw, salt); var validateResult = PasswordHasher.Validate(pw, salt, hash); Assert.IsTrue(validateResult); }
public void Hashes_Should_Be_Unique() { var pw1 = "thisispassword123"; var pw2 = "thisispassword12"; var salt = PasswordHasher.CreateSalt(); var hash1 = PasswordHasher.CreateHashedPassword(pw1, salt); var hash2 = PasswordHasher.CreateHashedPassword(pw2, salt); Assert.AreNotEqual(hash1, hash2); }
public async Task <Student> Register(Student user, string password) { if (await HasEntityAsync(user)) { throw new UserFoundException("This user already exists"); } PasswordHasher <Student, Guid> .CreateHashedPassword(password, out var hashedPass, out var saltPass); user.HashedPassword = hashedPass; user.SaltPassword = saltPass; return(await CreateAsync(user)); }
public async Task <Employer> Register(Employer user, string password) { var company = await _companiesRepository.GetByIdAsync(user.CompanyId); if (company == null) { throw new EntityNotFoundException("Such company doesn't exist"); } if (await HasEntityAsync(user)) { throw new UserFoundException("This user already exists"); } PasswordHasher <Employer, Guid> .CreateHashedPassword(password, out var hashedPass, out var saltPass); user.HashedPassword = hashedPass; user.SaltPassword = saltPass; return(await CreateAsync(user)); }