在使用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<>()
但我无法使用。
答案 0 :(得分:21)
在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;
});
// 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();
// 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();