public async Task<ActionResult> EditPassword(UserAdminEditPasswordViewModel input) { string id = input.Id; string password = input.Password; string confirmPassword = input.ConfirmPassword; AppUser user = await UserManager.FindByIdAsync(id); if (user == null) { ModelState.AddModelError("", "User Not Found"); return RedirectToAction("Index"); } UserAdminEditPasswordViewModel viewmodel = new UserAdminEditPasswordViewModel() { Id = user.Id, Email = user.Email }; if (input.Password == null) { ModelState.AddModelError("", "You must either enter a new Password or cancel!"); return View(viewmodel); } if (password != confirmPassword) { ModelState.AddModelError("", "Password and Confirm Password do not match!"); return View(viewmodel); } IdentityResult validPass = await UserManager.PasswordValidator.ValidateAsync(password); if (validPass.Succeeded) { user.PasswordHash = UserManager.PasswordHasher.HashPassword(password); } else { AddErrorsFromResult(validPass); return View(input); } IdentityResult result = await UserManager.UpdateAsync(user); if (result.Succeeded) { return RedirectToAction("Index"); } else { AddErrorsFromResult(result); return View(input); } }
// GET: Edit Password public async Task<ActionResult> EditPassword(string id) { AppUser user = await UserManager.FindByIdAsync(id); if (user == null) { return RedirectToAction("Index"); } var viewmodel = new UserAdminEditPasswordViewModel() { Id = user.Id, Email = user.Email, }; return View(viewmodel); }