我遵循了SO示例代码和官方文档 但是我更改了 Aspnet 中的密码长度核心 2.1 项目没有任何变化.我总是收到消息密码必须至少为 6 个字符,最长为 100 个字符."
I have followed the SO example code and the official documentation but however I change the password length in my Aspnet core 2.1 project nothing changes. I always get the message "The Password must be at least 6 and at max 100 characters long."
在public void ConfigureServices(IServiceCollection services)我试过了
services.Configure<IdentityOptions>(options => { options.Password.RequiredLength = 1; });在不同的地方,或者添加到AddDefaultIdentity
in various places, or adding it to AddDefaultIdentity<>
services.AddDefaultIdentity<IdentityUser>(options => options.Password.RequiredLength = 1; ) .AddEntityFrameworkStores<ApplicationDbContext>();但无济于事.
我正在使用 非脚手架版本,所以我无法访问 HTML 或 cshtml 文件.
I am using the non-scaffolded version so I don't have access to the HTML or cshtml files.
推荐答案您似乎找到了 bug 搭建脚手架的理由.在包含 ASP.NET Core Identity UI 的 Razor Pages 实现的 Razor 类库中,有一个 Register 页面的/Identity/Pages/Account/Register.cshtml.cs#L26" rel="noreferrer">InputModel 类,如下所示:
It looks like you've found a bug reason to scaffold. In the Razor Class Library that contains the Razor Pages implementation of the ASP.NET Core Identity UI, there's an InputModel class for the Register Page that looks like this:
public class InputModel { ... [Required] [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] [DataType(DataType.Password)] [Display(Name = "Password")] public string Password { get; set; } ... }从这段代码片段可以清楚地看出,无论您将 RequiredLength 设置为什么,内置的 ModelState 验证都需要 6 到 100 个字符的长度.
It's clear from this code snippet that no matter what you set RequiredLength to, the built-in ModelState validation will always require a length of between 6 and 100 characters.
还值得注意的是,这不仅会影响 Register 页面 - 我已经确认它还会影响 ResetPassword、SetPassword和 ChangePassword.
It's also worth noting that this doesn't just affect the Register page - I've confirmed that it also affects ResetPassword, SetPassword and ChangePassword.
就解决方案而言:Chris Pratt 在评论中指出,解决此问题的唯一真正方法是脚手架受影响的页面并对 StringLength 属性进行必要的更改.
In terms of a solution: Chris Pratt has pointed out in the comments that the only real way to resolve this is to scaffold the affected pages and make the necessary changes to the StringLength attributes.
更新:您提出的问题已作为副本关闭,解决方案是搭建页面并进行必要的更改.
Update: The issue you've raised has been closed as a duplicate, with the solution being to scaffold the Pages and make the required change.
更多推荐
如何在 Aspnet Core 2.1 中设置密码选项
发布评论