如何在asp.net会员中比较密码和用户名?

发布于 2024-12-26 05:36:05 字数 539 浏览 3 评论 0原文

在创建具有 ASP.NET 成员身份的用户之前,如何确保输入的密码与输入的用户名不匹配?

更新:

我已经尝试设置此设置(在 web.config 文件提供程序部分):

passwordStrengthRegularExpression = "^(?:(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])|(?=.*[a-z])(?=.*[A-Z])(?=.*[!%,.;:])|(?=.*[a-z])(?=.*[0-9])(?=.*[!%,.;:])|(?=.*[A-Z])(?=.*[0-9])(?=.*[!%,.;:]))(?i)(?!.*" + Username + ").+$";

但恐怕将其与这样的用户名进行比较在会员资格中不起作用。

我还认为可以通过一些自定义验证来装饰 AccountModelRegisterModel 类的 Password 属性。

不管怎样,我很困惑,需要建议。

How can you ensure an entered password does not match an entered username before creating a user with ASP.NET Membership?

Update:

I've tried setting this (in the web.config file provider section):

passwordStrengthRegularExpression = "^(?:(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])|(?=.*[a-z])(?=.*[A-Z])(?=.*[!%,.;:])|(?=.*[a-z])(?=.*[0-9])(?=.*[!%,.;:])|(?=.*[A-Z])(?=.*[0-9])(?=.*[!%,.;:]))(?i)(?!.*" + Username + ").+$";

But I'm afraid comparing it to the username like this won't work in Membership.

I also thought I could decorate the Password property of the RegisterModel class in AccountModel with some custom validation.

Either way I am confused and need suggestions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梅窗月明清似水 2025-01-02 05:36:05

这不是一个直接的答案,但如果您在 MembershipProvider 配置中设置了最低密码复杂性要求,那么出现这种情况的可能性应该很小。

这是在以下 web.config 块中完成的(例如):

<membership>
    <providers>
        <clear/>
        <add connectionStringName="xxx" 
             requiresQuestionAndAnswer="false" 
             maxInvalidPasswordAttempts="5" 
             minRequiredPasswordLength="8" 
             minRequiredNonalphanumericCharacters="1" 
             passwordAttemptWindow="5" 
             passwordStrengthRegularExpression="(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).*$" 
             applicationName="/" 
             name="AspNetSqlMembershipProvider" 
             type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
    </providers>      
</membership>

It's not a direct answer, but if you set minimum password complexity requirements in the MembershipProvider configuration, then there should be little chance of this.

This is done in the following web.config block (for example):

<membership>
    <providers>
        <clear/>
        <add connectionStringName="xxx" 
             requiresQuestionAndAnswer="false" 
             maxInvalidPasswordAttempts="5" 
             minRequiredPasswordLength="8" 
             minRequiredNonalphanumericCharacters="1" 
             passwordAttemptWindow="5" 
             passwordStrengthRegularExpression="(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).*$" 
             applicationName="/" 
             name="AspNetSqlMembershipProvider" 
             type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
    </providers>      
</membership>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文