【发布时间】:2015-05-30 15:16:47
【问题描述】:
我在“ForgotPassword”之后有一个“ForceChangePassword”页面,它在“NewPassword”字段上随机抛出两个长度要求。问题是,我从未添加 7 的长度要求,也不知道它来自哪里或如何更改它。
来自模型状态的错误
The New password must be at least 6 characters long.
The 'New password' field is an invalid password. Password must have 7 or more characters.
if (!ModelState.IsValid) { return View(model); } // Only line executed in the POST Action.
我通过属性在 ViewModel 上将长度要求设置为 6(见下文)。我不知道 7 的要求是从哪里来的。
IdentityConfig.cs
manager.PasswordValidator = new PasswordValidator
{
RequiredLength = 6,
RequireNonLetterOrDigit = true,
RequireDigit = true,
RequireLowercase = true,
RequireUppercase = true,
};
型号
[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; }
查看
<div class="form-group">
@Html.LabelFor(m => m.NewPassword, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.PasswordFor(m => m.NewPassword, new { @class = "form-control", @autocomplete = "off" })
</div>
</div>
罪魁祸首属性:
data-val-password-min="7"
问题:在使用 Identity 2.0 的 MVC 5 项目中添加密码长度验证的可能位置在哪里?会不会有某种我没有设置的默认要求?
注意:如有必要,我会添加更多代码,但我已经发布了我知道的所有可能相关的代码。没有其他内容提到密码(据我所知,如果有更多位置,请告诉我)。
【问题讨论】:
标签: asp.net asp.net-mvc-5 asp.net-identity-2