从哪里获得会员密码()要求?
Where to set MembershipPassword() requirments?
所选答案 显示了一种如何设置要求的方法,但我希望在仍然使用 MembesshipPassowrd() 验证属性的同时使这些规则更具可重用性,我认为可以通过在我的扩展成员资格提供商中指定角色,但我找不到任何关于如何完成此操作的文档。
如何在我的 custom/extended 会员提供商中包含密码要求?
型号
[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; }
似乎 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 有这方面的详细信息。
所选答案
如何在我的 custom/extended 会员提供商中包含密码要求?
型号
[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; }
似乎 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 有这方面的详细信息。