public void ValidatePassword_CorrectPassword_ShouldReturnTrue() { var user = PasswordHashService.HashPassword("Pa55word"); bool result = PasswordHashService.ValidatePassword("Pa55word", user); Assert.IsTrue(result); }
public void ValidatePassword_WrongPassword_ShouldReturnFalse() { var user = PasswordHashService.HashPassword("Pa55word"); bool result = PasswordHashService.ValidatePassword("Password", user); Assert.IsFalse(result); }
static void Main(string[] args) { var hasher = new PasswordHashService(); Console.Write("Password : "******"Password Hash: {passwordHash}"); Console.ReadLine(); }
public void HashPassword_CorrectData_ShouldReturnHashedPassword() { string password = "******"; string hashedPass = String.Empty; string salt = String.Empty; for (int i = 0; i < 50; i++) { var user = PasswordHashService.HashPassword(password); var newHashedPass = user.PasswordHash; var newSalt = user.Salt; Assert.That(hashedPass, Is.Not.EqualTo(newHashedPass)); Assert.That(salt, Is.Not.EqualTo(newSalt)); hashedPass = newHashedPass; salt = newSalt; } }
public async Task <IActionResult> Register([FromBody] RegisterRequest request) { string hashedPassword = PasswordHashService.HashPassword(request.Password); var user = new User { Email = request.Email, UserName = request.UserName, Password = hashedPassword }; User registeredUser = await _userService.RegisterAsync(user); if (registeredUser != null) { ClaimsPrincipal claimsPrincipal = _userService.CreateClaimsPrinciple(user); await Request.HttpContext.SignInAsync("Cookies", claimsPrincipal); return(Ok(new { test = "test" })); } return(BadRequest()); }