public async Task<ActionResult> ResetPassword(ResetPasswordViewModel model) { if (!ModelState.IsValid) { return View(model); } var user = await UserManager.FindByNameAsync(model.UserName); if (user == null) { // 不顯示使用者不存在 return RedirectToAction("ResetPasswordConfirmation", "Account"); } // 原本的 //var result = await UserManager.ResetPasswordAsync(user.Id, model.Code, model.Password); // 刪除原本的密碼後再重新設定 UserManager.RemovePassword(user.Id); var result = UserManager.AddPassword(user.Id, model.Password); if (result.Succeeded) { return RedirectToAction("ResetPasswordConfirmation", "Account"); } AddErrors(result); return View(); }
public ActionResult ResetPassword() { ResetPasswordViewModel resetPasswordViewModel = new ResetPasswordViewModel() { UserName = loginUser.UserName, Password = null, ConfirmPassword = null }; return View(resetPasswordViewModel); }