private User InitUser(RegisterModel model, int userRoleId) { var passwordHasher = new BCryptPasswordHasher <User>(); return(new User { Username = model.Username, Email = model.Email, UserRoleId = userRoleId, Password = passwordHasher.HashPassword(null, model.Password) }); }
public async Task <IActionResult> UpdatePassword([FromBody] PasswordModel model, [FromServices] UserService userService) { var user = await userService.GetUserPrincipal(User); var passwordHasher = new BCryptPasswordHasher <User>(); var compare = passwordHasher.VerifyHashedPassword(null, model.CurrentPassword, user.Password); if (compare != PasswordVerificationResult.Success) { return(Unauthorized()); } var hashedPassword = passwordHasher.HashPassword(null, model.UpdatePassword); user = await userService.Update(user.Id, hashedPassword); if (user != null) { return(Ok(model)); } return(BadRequest(HttpStatus.SERVER_ERROR)); }