Note that there are some explanatory texts on larger screens.

plurals
  1. POPassword change was unsuccessful. Please correct the errors and try again.
    primarykey
    data
    text
    <p>I can't change my password when I run my application. It always stuck up on Validation Summary and I can't change my password.Is there something on the code that need to change or configuration is needed? This is the error I receive.</p> <blockquote> <p>Password change was unsuccessful. Please correct the errors and try again. The current password is incorrect or the new password is invalid.</p> </blockquote> <p>But I am sure that I type my current password correctly.</p> <p><strong>MODEL</strong> AccountModel.cs</p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Globalization; using System.Web.Mvc; using System.Web.Security; namespace Customer.Models { public class ChangePasswordModel { [Required] [DataType(DataType.Password)] [Display(Name = "Current password")] public string OldPassword { get; set; } [Required] [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] [DataType(DataType.Password)] [Display(Name = "New password")] public string NewPassword { get; set; } [DataType(DataType.Password)] [Display(Name = "Confirm new password")] [Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")] public string ConfirmPassword { get; set; } } } </code></pre> <p><strong>Controller</strong></p> <pre><code>// GET: /Account/ChangePassword [Authorize] public ActionResult ChangePassword() { return View(); } // POST: /Account/Register [HttpPost] public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user //MembershipCreateStatus createStatus; try { MembershipService.CreateUser(model.UserName, model.FullName, model.Password, model.Email); //if (createStatus == MembershipCreateStatus.Success) //{ FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */); return RedirectToAction("Index", "Home"); //} } catch(ArgumentException ae) { ModelState.AddModelError("", ae.Message); } } // If we got this far, something failed, redisplay form return View(model); } // POST: /Account/ChangePassword [Authorize] [HttpPost] public ActionResult ChangePassword(ChangePasswordModel model) { if (ModelState.IsValid) { // ChangePassword will throw an exception rather // than return false in certain failure scenarios. bool changePasswordSucceeded; try { MembershipUser currentUser = Membership.GetUser(User.Identity.Name, true); changePasswordSucceeded = currentUser.ChangePassword(model.OldPassword, model.NewPassword); } catch (Exception) { changePasswordSucceeded = false; } if (changePasswordSucceeded) { return RedirectToAction("ChangePasswordSuccess"); } else { ModelState.AddModelError("", "The current password is incorrect or the new password is invalid."); } } // If we got this far, something failed, redisplay form return View(model); } // GET: /Account/ChangePasswordSuccess public ActionResult ChangePasswordSuccess() { return View(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload