如何在Aspnet Core 2.1中设置密码选项

编程入门 行业动态 更新时间:2024-10-27 22:32:56
本文介绍了如何在Aspnet Core 2.1中设置密码选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我遵循了 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类库中,有一个 InputModel 类用于Register页面,如下所示:

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中设置密码选项

本文发布于:2023-11-16 06:31:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1601841.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:选项   密码   如何在   Core   Aspnet

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!