gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 21:56:25 25 4
gpt4 key购买 nike

在 Asp.Net MVC 5 中使用 Identity,可以执行以下操作:

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

关于asp.net-mvc - 如何在MVC6或AspNet Core或IdentityCore中更改PasswordValidator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30942325/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com