Exemplo n.º 1
0
 public async Task <IActionResult> ChangePassword(ChangeUserPasswordVm change)
 {
     if (ModelState.IsValid)
     {
         if (await _userServices.ChangeUserPassword(change))
         {
             return(RedirectToAction("Edit", new { id = change.UserId }));
         }
     }
     return(View());
 }
Exemplo n.º 2
0
        public async Task <bool> ChangeUserPassword(ChangeUserPasswordVm changeUserPassword)
        {
            try
            {
                var user = await _context.Users.FindAsync(changeUserPassword.UserId);

                if (changeUserPassword.Password != changeUserPassword.RePassword)
                {
                    return(false);
                }

                var hashPassword = PasswordHelper.EncodePasswordMd5(changeUserPassword.Password);
                user.UserPassword = hashPassword;
                _updateUser(user);

                await _context.SaveChangesAsync();

                return(true);
            }
            catch
            {
                return(false);
            }
        }