Пример #1
0
        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)
            });
        }
Пример #2
0
        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));
        }