Adding Password Minimum Requirements for Identity

It is very simple to add validation to check for minimum password requirements when creating an Identity user. Simply add the following data attributes to the model or metadata file. The regular expression attribute will check to make sure that the password contains at least one capitol letter, lower case letter, number, special character and is at least 8 characters in length.

[Required]
[DataType(DataType.Password)]
[RegularExpression(@"^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%&*()_+=|<>?{}\\[\\]~-])[0-9a-zA-Z!@#$%&*()_+=|<>?{}\\[\\]~-]{8,}$", ErrorMessage = "Passwords must contain 8 characters and at least 1 capitol, 1 lowercase, 1 number and 1 special character.")]
public string Password { get; set; }

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *