Last active
November 25, 2019 06:04
-
-
Save bcnzer/9ec872a30551bfb358324c83fc9579d9 to your computer and use it in GitHub Desktop.
Registration view model with a complex password requirement
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RegisterViewModel | |
{ | |
[Required] | |
[Display(Name = "First Name")] | |
[StringLength(100, ErrorMessage = "{0} must be at least {2} characters long.", MinimumLength = 2)] | |
public string FirstName { get; set; } | |
[Required] | |
[Display(Name = "Last Name")] | |
[StringLength(100, ErrorMessage = "{0} must be at least {2} characters long.", MinimumLength = 2)] | |
public string LastName { get; set; } | |
[Required] | |
[EmailAddress] | |
[Display(Name = "Email")] | |
public string Email { get; set; } | |
[Required] | |
[EmailAddress] | |
[Compare("Email", ErrorMessage = "The email addresses do not match.")] | |
[Display(Name = "Confirmation Email")] | |
public string EmailConfirm { get; set; } | |
[Required] | |
[DataType(DataType.Password)] | |
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 8)] | |
[Display(Name = "Password")] | |
[RegularExpression("^((?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])|(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[^a-zA-Z0-9])|(?=.*?[A-Z])(?=.*?[0-9])(?=.*?[^a-zA-Z0-9])|(?=.*?[a-z])(?=.*?[0-9])(?=.*?[^a-zA-Z0-9])).{8,}$", ErrorMessage = "Passwords must be at least 8 characters and contain at 3 of 4 of the following: upper case (A-Z), lower case (a-z), number (0-9) and special character (e.g. !@#$%^&*)")] | |
public string Password { get; set; } | |
[DataType(DataType.Password)] | |
[Display(Name = "Confirm password")] | |
[Compare("Password", ErrorMessage = "The passwords do not match.")] | |
public string ConfirmPassword { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment