asp.net 会员资格如何在创建新用户/更改密码时限制密码属性?

发布于 2024-12-26 01:17:00 字数 365 浏览 4 评论 0原文

我想使用下面提到的属性来限制密码强度:: 密码强度:

  • 1.包含以下四类中三类的字符:

英文大写字符(A 到 Z)
英文小写字符(a 到 z)
10 基数(0 到 9)
非字母字符(例如,!、$、#、%)

  • 2.密码不包含用户的帐户名


通过向 PasswordStrengthRegularExpression 属性在 web.config 文件中的membership 部分
但问题是第二个(密码不包含用户的帐户名)我应该做什么来实现这一点。

I want to restrict password strength with below mentioned properties::
Password strength:

  • 1.Contain characters from three of the following four categories:

English uppercase characters (A through Z)
English lowercase characters (a through z)
Base 10 digits (0 through 9)
Non-alphabetic characters (for example, !, $, #, %)

  • 2.password Not contain the user's account name

I can easily achieve 1st condition by providing regex to PasswordStrengthRegularExpression attribute in web.config file under membership section
But the problem is with 2nd one(password Not contain the user's account name) what should i do to achieve that.

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

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

发布评论

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

评论(1

挥剑断情 2025-01-02 01:17:00

检查我在下一篇文章中链接到的页面。

基本上,您编写自己的数据注释,因此您应该能够修改它以查看密码是否包含用户名而不是等于用户名。

与 .net 中的 [compare(" ")] 数据注释相反?

我刚刚意识到你也提出了这个问题。

因此,您应该将博客文章中的类名更改为“CanNotContainAttribute”之类的内容
然后也将构造函数更改为相同的名称。

在IsValid 方法中,您应该检查一个字符串是否包含另一个字符串,即Password 是否包含Username,如果注释应用于模型文件中的password 属性,则此处的Username 称为OtherProperty。

然后,您可以通过执行以下操作将注释应用于密码属性:

[CanNotContain("UserName")]
public string Password { get; set; }

我引用的原始博客文章是: http://www.devtrends.co.uk/blog/the-complete-guide-to-validation-in-asp.net-mvc-3-part-2

Check the page I link to in the following post.

Basically, you write your own Dataannotation, so you should be able to modify it to see if the password contains the username instead of being equal to the username.

Opposite of [compare(" ")] data annotation in .net?

I just realised you posted that question also.

So you should change the classname in the blogpost to something like "CanNotContainAttribute"
and then also change to the same name for the constructor.

In the IsValid method, you should check if one string contains the other, i.e. if Password contains Username, where Username is here refered to as the OtherProperty if the annotation is applied to the password property in the model file.

And then you apply the annotation to the Password property by doing:

[CanNotContain("UserName")]
public string Password { get; set; }

The original blog post I refer to is: http://www.devtrends.co.uk/blog/the-complete-guide-to-validation-in-asp.net-mvc-3-part-2

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文