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的概念,先从...
基于 .NET 的一个全新的、好用的 PHP SDK + Runtime: Pe...
.NET 异步工作原理介绍。
引子 .NET 6 开始初步引入 PGO。PGO 即 Profile Guided Opti...
前言 2021/4/8 .NET 6 Preview 3 发布,这个版本的改进大多来...
前言 开头防杠:.NET 的基础库、语言、运行时团队从来都是相...