问题描述
ASP.NET中5提供的默认身份提供具有由缺省非常严格的密码规则,要求一个小写字符,大写字符,一个非字母数字字符,以及一个数字。我正在寻找一种方法来改变提供程序的密码要求。
The default Identity provider provided in ASP.NET 5 has very strict password rules by default, requiring a lower case character, an upper case character, a non-alphanumeric character, and a number. I am looking for a way to change the password requirements for the provider.
previously在ASP.NET 4,供应商可以通过在Web.config的XML文件进行配置,如$p$pviously回答。然而ASP.NET 5采用了全新的code基于配置模式,目前还不清楚如何配置身份。
Previously in ASP.NET 4, the provider could be configured via the Web.config XML file, as previously answered. However ASP.NET 5 uses the new code based configuration pattern and it is unclear how to configure the identity.
如何更改密码要求为我的应用程序?
How can I change the password requirements for my application?
推荐答案
其实我最终搞清楚了这一点,事实证明你需要与配置它提供了IdentityOptions合适LAMDA前pression供应AddDefaultIdentity。这是在ConfigureServices方法内部完成启动类中,像这样:
I actually ended up figuring this out, it turns out you need to supply AddDefaultIdentity with a suitable lamda expression that configures the IdentityOptions it provides. This is done inside the ConfigureServices method within the Startup class, like so:
public class Startup {
public void ConfigureServices(IServiceCollection services) {
// Add Identity services to the services container.
services.AddDefaultIdentity<ApplicationIdentityDbContext, ApplicationUser, IdentityRole>(Configuration,
o => {
o.Password.RequireDigit = false;
o.Password.RequireLowercase = false;
o.Password.RequireUppercase = false;
o.Password.RequireNonLetterOrDigit = false;
o.Password.RequiredLength = 7;
});
}
}
beta5的它有所更改为:
The above was true in the beta1 versions of the framework, in the latest beta5 it has changed slightly to:
services.AddIdentity<ApplicationUser, IdentityRole>(o => {
// configure identity options
o.Password.RequireDigit = false;
o.Password.RequireLowercase = false;
o.Password.RequireUppercase = false;
o.Password.RequireNonLetterOrDigit = false;;
o.Password.RequiredLength = 6;
})
.AddEntityFrameworkStores<ApplicationIdentityDbContext>()
.AddDefaultTokenProviders();
这篇关于如何定义在ASP.NET MVC 5 6(vNext)为身份的密码规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!