我正在使用带有func (node *Node) GetParent() GraphNode {
return node.parent
}
身份验证的默认ASP.NET Core 1.1模板。 Individual User Accounts
上的以下代码抱怨密码要求(例如长度要求,大写,小写等)。我知道我们可以使用VS2015
在内置RegisterViewModel
上设置这些要求。但由于我在不使用任何ViewModel的情况下以编程方式创建用户,DataAnnotations
将无法正常工作。 问题:如何更改密码要求并能够运行以下代码:
DataAnnotations
答案 0 :(得分:1)
您可以在AddIdentity方法中添加选项......
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<ApplicationUser, IdentityRole>(options =>
{
options.Password.RequireDigit = false;
options.Password.RequireLowercase = false;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = false;
options.Password.RequiredLength = 1;
options.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@.";
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc();
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
}
答案 1 :(得分:0)
Microsoft Docs网站上有一个最新的教程。
Introduction to Identity on ASP.NET Core
您可以使用的其他设置的示例代码中有更多信息,例如“options.Password”。