asp.net-mvc 如何更改 ASP.Net MVC Identity 2 中的密码验证?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24796454/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 03:46:31  来源:igfitidea点击:

How To Change Password Validation in ASP.Net MVC Identity 2?

asp.net-mvcasp.net-identityasp.net-identity-2

提问by Nazmul Hossain

How To Change Password Validation in ASP.Net MVC5 Identity 2 ?

如何更改 ASP.Net MVC5 Identity 2 中的密码验证?

Thanks

谢谢

回答by Anthony Chu

In the MVC project template in VS2013 Update 2, there should be a file called App_Start/IdentityConfig.cs. In it you should find the class ApplicationUserManagerand a static factory method called Create(). That's where the user manager class is configured, including the server-side validation rules for passwords are defined. For example:

在 VS2013 Update 2 的 MVC 项目模板中,应该有一个名为App_Start/IdentityConfig.cs. 在其中,您应该找到类ApplicationUserManager和一个名为 的静态工厂方法Create()。这是配置用户管理器类的地方,包括定义密码的服务器端验证规则。例如:

manager.PasswordValidator = new PasswordValidator
{
    RequiredLength = 6,
    RequireNonLetterOrDigit = true,
    RequireDigit = true,
    RequireLowercase = true,
    RequireUppercase = true,
};

回答by nanonerd

In addition to Anthony Chu's answer,

除了 Anthony Chu 的回答,

You may also need to change it in Models folder > AccountViewModel.cs > class RegisterViewModel (as well as class ResetPasswordViewModel)

您可能还需要在 Models 文件夹 > AccountViewModel.cs > class RegisterViewModel(以及类 ResetPasswordViewModel)中更改它

Change "MinimumLength = 6" (need to scroll right)

更改“MinimumLength = 6”(需要向右滚动)

 [Required]
 [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
 [DataType(DataType.Password)]
 [Display(Name = "Password")]
 public string Password { get; set; }