加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-15 20:10:23 所属栏目:asp.Net 来源:网络整理
导读:在使用Identity的Asp.Net MVC 5中,可以执行以下操作: manager.PasswordValidator = new PasswordValidator { RequiredLength = 6,RequireLowercase = true,RequireDigit = false,RequireUppercase = false }; 如何在MVC 6中更改相同的配置? 我看到可以在段
在使用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();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读