在使用Identity的Asp.Net MVC 5中,可以执行以下操作:
manager.PasswordValidator = new PasswordValidator
{
RequiredLength = 6,
RequireLowercase = true,
RequireDigit = false,
RequireUppercase = false
};
如何在MVC 6中更改相同的配置?
我看到可以在该段的ConfigurationServices方法中:
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddPasswordValidator<>()
但是我不能用。
最佳答案
解决方案Beta6
在Startup.cs
中编写代码:
services.ConfigureIdentity(options =>
{
options.Password.RequireDigit = false;
options.Password.RequiredLength = 6;
options.Password.RequireLowercase = false;
options.Password.RequireNonLetterOrDigit = false;
options.Password.RequireUppercase = false;
});
更新Beta8和RC1
// Add Identity services to the services container.
services.AddIdentity<ApplicationUser, IdentityRole>(options =>
{
options.Password.RequireDigit = false;
options.Password.RequiredLength = 6;
options.Password.RequireLowercase = false;
options.Password.RequireNonLetterOrDigit = false;
options.Password.RequireUppercase = false;
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
更新RC2
// Add Identity services to the services container.
services.AddIdentity<ApplicationUser, IdentityRole>(options =>
{
options.Password.RequireDigit = false;
options.Password.RequiredLength = 6;
options.Password.RequireLowercase = false;
options.Password.RequireNonAlphanumeric= false;
options.Password.RequireUppercase = false;
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
关于asp.net-mvc - 如何在MVC6或AspNet Core或IdentityCore中更改PasswordValidator,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30942325/