How can I make RequiredLength of identity to work. I already try to change the value of RequiredLength to 10, but i still can register using 6 password. when i try to change it to RequiredLength to 5, it doesnt work. It said password need to be atleast 6 length. I also modified the viewmodels but same thing happen, I think it was stuck in RequiredLength = 6. I also try to clean and rebuild my project.
manager.PasswordValidator = new PasswordValidator
{
RequiredLength = 10,
RequireNonLetterOrDigit = false,
RequireDigit = false,
RequireLowercase = false,
RequireUppercase = false,
};
EDIT: working on register account, but not working on change password
Hi you can use Data Annotation Feature to achieve by decorating the entity field with validator.
[Required]
[StringLength(10)]
public string RequiredLength { get; set; }
In your ViewModel add an attribute to your Password property:
[MinLength(10,ErrorMessage = "Minimum length of 10 characters is required")]
public string Password { get; set; }
On your post method in the controller check for ModelState.IsValid:
public ActionResult Login(YourLoginViewModel model)
{
if (ModelState.IsValid)
{
//Your Login logic here
}
else
{
return View(model)
}
}
Finally in your view add ValidationSummary to display error:
@Html.ValidationSummary("")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With