asp.net-mvc – 如何在MVC6或AspNet Core或IdentityCore中更改PasswordValidator

前端之家收集整理的这篇文章主要介绍了asp.net-mvc – 如何在MVC6或AspNet Core或IdentityCore中更改PasswordValidator前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在使用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();

猜你在找的.NET Core相关文章