MVC 4 and simplemembership, how to set password format?

609 views Asked by At

I am using MVC4 and simplemembership to create a web application.

Where or how do I set the password requirements? ie - that the password needs to be a minimum 6 characters - needs one alpha numeric - needs one capital etc

I thought it was in the web config?

Thanks in advance

1

There are 1 answers

0
Jeroen Vannevel On BEST ANSWER

In AccountsModels.cs there is a class RegisterModel. You can annotate the properties there to add validation:

[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }

For the specific requirements you can add a Regex that suits your needs with the [RegularExpression] annotation.