So, in MVC, when using the .NET Membership system, password policies are defined in the web.config file. For example, minPasswordLength is defined in membership-> profiles.
When using View, this is available using the @Membership component
Passwords must be at least @Membership.MinRequiredPasswordLength characters long.
However, if you look at the default model in the MVC application example, it says
[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; }
The parts that interest me are MinimumLength = 6 , since it is hardcoded, it would mean that if I ever wanted to update the password length, I would have to not only edit web.config (e.g. Microsoft) but also look any references to it in the source and modify everywhere (perhaps not the best programming practice).
Are there any ways to use variables in attributes. I suspect that since this probably happens at compile time and not at runtime. If not, does anyone know a better pattern to stop me from finding a replacement for all links in the future?
source share