如何在 MVC6 或 AspNet Core 或 IdentityCore 中更改 PasswordValidator

How to change PasswordValidator in MVC6 or AspNet Core or IdentityCore

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