How do I define the password rules for Identity in ASP.NET 5 MVC 6 (vNext)?(如何在 ASP.NET 5 MVC 6 (vNext) 中定义 Identity 的密码规则?)
问题描述
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.
以前在 ASP.NET 4 中,可以通过 Web.config XML 文件配置提供程序,如 以前回答过.但是 ASP.NET 5 使用新的基于代码的配置模式,不清楚如何配置身份.
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?
推荐答案
我实际上最终弄清楚了这一点,事实证明您需要为 AddDefaultIdentity 提供一个合适的 lambda 表达式来配置它提供的 IdentityOptions.这是在 Startup 类的 ConfigureServices 方法中完成的,如下所示:
I actually ended up figuring this out, it turns out you need to supply AddDefaultIdentity with a suitable lambda 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;
});
}
}
更新 2:
上述在框架的 beta1 版本中是正确的,在最新的 rc1 beta5 中它略微更改为:
The above was true in the beta1 versions of the framework, in the latest rc1 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.RequireNonAlphanumeric = false;
o.Password.RequiredLength = 6;
})
.AddEntityFrameworkStores<ApplicationIdentityDbContext>()
.AddDefaultTokenProviders();
这篇关于如何在 ASP.NET 5 MVC 6 (vNext) 中定义 Identity 的密码规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 ASP.NET 5 MVC 6 (vNext) 中定义 Identity 的密码规则?
基础教程推荐
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 将数据集转换为列表 2022-01-01
- 如果条件可以为空 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
