在使用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();