选择的答案here显示了如何设置要求的一种方法,但我希望在使用MembeshipPassowrd()验证属性的同时使这些规则更可重用,我认为可以通过指定我的扩展成员资格提供者中的角色,但我找不到任何关于如何做到这一点的文档。
如何在我的自定义/扩展成员资格提供程序中包含密码要求?
模型
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[MembershipPassword(
MinRequiredNonAlphanumericCharacters = 1,
MinNonAlphanumericCharactersError = "Your password needs to contain at least one symbol (!, @, #, etc).",
ErrorMessage = "Your password must be 6 characters long and contain at least one symbol (!, @, #, etc)."
)]
[DataType(DataType.Password)]
[Display(Name = "New password")]
public string NewPassword { get; set; }
答案 0 :(得分:0)
似乎PasswordStrngthRegularExpression是执行此操作所需的,可以通过覆盖它在web.config文件或扩展成员资格提供程序中设置:
public override string PasswordStrengthRegularExpression
{
get { return @"(?=.{5,})(?=(.*\d){1,})(?=(.*\W){1,})(?=.*[a-z])(?=.*[A-Z])"; }
}
或强>
<membership defaultProvider="SqlProvider"
userIsOnlineTimeWindow = "20>
<providers>
<add
name="SqlProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="SqlServices"
requiresQuestionAndAnswer="true"
passwordStrengthRegularExpression="@\"(?=.{6,})(?=(.*\d){1,})(?=(.*\W){1,})"
/>
</providers>
</membership>
MSDN有详细说明。