How to change PasswordValidator in MVC6 or AspNet Core or IdentityCore

丶灬走出姿态 提交于 2019-12-21 10:00:17

问题


In the Asp.Net MVC 5 using Identity, was possible to do the following:

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

How to change the same configuration in MVC 6?

I see that can be in ConfigurationServices method in the segment:

 services.AddIdentity<ApplicationUser, IdentityRole>()
         .AddPasswordValidator<>()

But I could not use.


回答1:


The Solution Beta6

In the Startup.cs write the code:

          services.ConfigureIdentity(options =>
            {
                options.Password.RequireDigit = false;
                options.Password.RequiredLength = 6;
                options.Password.RequireLowercase = false;
                options.Password.RequireNonLetterOrDigit = false;
                options.Password.RequireUppercase = false;
            });

Update Beta8 and 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();

Update 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();


来源:https://stackoverflow.com/questions/30942325/how-to-change-passwordvalidator-in-mvc6-or-aspnet-core-or-identitycore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!