我使用Asp.net身份设置IdentityServer4。
如何配置最小密码长度以及是否需要输入数字之类的项目?
通常在MVC项目中配置身份时,我会这样做:
manager.PasswordValidator = new PasswordValidator
{
RequiredLength = 6,
RequireNonLetterOrDigit = false,
RequireDigit = false,
RequireLowercase = false,
RequireUppercase = false,
};
但是我不知道如何在我的ID4项目中设置它。
在我的startup.cs中,我有以下内容:
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc();
services.Configure<IISOptions>(iis =>
{
iis.AuthenticationDisplayName = "Windows";
iis.AutomaticAuthentication = false;
});
var builder = services.AddIdentityServer(options =>
{
options.Events.RaiseErrorEvents = true;
options.Events.RaiseInformationEvents = true;
options.Events.RaiseFailureEvents = true;
options.Events.RaiseSuccessEvents = true;
})
.AddInMemoryIdentityResources(Config.GetIdentityResources())
.AddInMemoryApiResources(Config.GetApis())
.AddInMemoryClients(Config.GetClients())
.AddAspNetIdentity<ApplicationUser>();
答案 0 :(得分:0)
您需要将其配置为选项。
services.AddIdentity<ApplicationUser, IdentityRole>(options =>
{
//options.SignIn.RequireConfirmedEmail = true;
//User validator
options.User.RequireUniqueEmail = true;
//Password Validator
options.Password.RequireDigit = true;
options.Password.RequiredLength = 6;
options.Password.RequireUppercase = true;
options.Password.RequireLowercase = true;
options.Password.RequireNonAlphanumeric = true;
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();