【发布时间】:2019-09-08 06:30:55
【问题描述】:
在脚手架身份验证之后,我很难更改身份选项。
我使用了这个命令:
dotnet new webapp --auth Individual -o mywebapp
然后,我更改了 Startup.cs 文件,更改了身份选项:
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<IdentityUser>(config =>
{
// TODO
//config.SignIn.RequireConfirmedEmail = true;
})
.AddDefaultUI(UIFramework.Bootstrap4)
.AddEntityFrameworkStores<ApplicationDbContext>();
services.Configure<IdentityOptions>(options =>
{
// Password settings
options.Password.RequireDigit = true;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = false;
options.Password.RequireLowercase = false;
options.Password.RequiredLength = 3;
options.Password.RequiredUniqueChars = 1;
// Lockout settings
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(5);
options.Lockout.MaxFailedAccessAttempts = 5;
options.Lockout.AllowedForNewUsers = true;
// User settings
options.User.RequireUniqueEmail = true;
});
设置options.Password.RequiredLength 无效。
当我运行应用程序时,浏览器显示错误消息:
The Password must be at least 6 and at max 100 characters long.
我没有预料到错误“至少 6”;从我读到的应该是“3”。 我该如何解决这个问题?
这么多的黑魔法正在发生,搜索“至少”的框架什么也没有发现。
编辑---> 添加搭建好的 ViewModel 代码:
namespace netplus.Models.Account
{
public class RegisterViewModel
{
[Required, MaxLength(256)]
public string Username { get; set; }
[Required, DataType(DataType.Password)]
public string Password { get; set; }
[DataType(DataType.Password), Compare(nameof(Password))]
public string ConfirmPassword { get; set; }
}
}
【问题讨论】:
-
@KirkLarkin 是的,看起来确实如此,并且在链接到 Github 之后,将错误显示为“Identity ignoring RequiredLength #774”,并且日期为 2016 年 3 月 16 日。想知道它是否真的是重复的因为在 asp.net core 2.2.0 中还没有修复。
-
我对您配置项目的方式并不完全清楚,所以我也不确定它是否重复。我不明白你为什么有
RegisterViewModel以及它来自哪里。您描述的错误消息来自“默认用户界面”,所以我认为这很可能是同一个问题。 -
@KirkLarkin,我开始了一个简单的项目(使用 Mac Visual Studio),新的解决方案,Web Application MVC .Net Core。我进入命令行并运行此命令以添加身份验证“dotnet new webapp --auth Individual”,然后我运行项目并尝试更改所需的密码长度,因为这只会妨碍我手动测试;然后我注意到控制密码长度的选项没有效果。
-
这听起来像是我链接的同一个问题,@TaoZhou 已经回答了 - 你显示的命令不应该生成这样的
RegisterViewModel类,所以这有点这里令人困惑。
标签: c# asp.net-core