ASP .Net 会员资格(控制在哪里从配置窗口创建新用户?)
这是我的 Web.config 文件
<membership>
<providers>
<clear />
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="8" minRequiredNonalphanumericCharacters="0" passwordStrengthRegularExpression="^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])|(?=.*[a-z])(?=.*[A-Z])(?=.*[!%,.;:])|(?=.*[a-z])(?=.*[0-9])(?=.*[!%,.;:])|(?=.*[A-Z])(?=.*[0-9])(?=.*[!%,.;:])$" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
在这里我想用几个条件限制新用户密码::
密码强度:
- 包含以下四个类别中三个类别的字符: 英文大写字符(A 到 Z)
英文小写字符(a 到 z)
10 基数(0 到 9)
非字母字符(例如 !、$、#、%)
- - 密码不包含用户的帐户名
正如您所看到的,我在 web.config 部分中使用了 passwordStrengthRegularExpression 属性来匹配第一个条件(会员提供的)。
需要解决方案来实现第二个条件。
简而言之:: 我需要自定义成员资格以匹配条件(强制执行字符复杂性。即:密码不包含用户的帐户名)
更新::
我按照埃兰加在我的申请中建议的去做了。现在我还想在会员创建用户失败时显示适当的消息(在几个自定义条件下)。
Here is my Web.config file
<membership>
<providers>
<clear />
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="8" minRequiredNonalphanumericCharacters="0" passwordStrengthRegularExpression="^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])|(?=.*[a-z])(?=.*[A-Z])(?=.*[!%,.;:])|(?=.*[a-z])(?=.*[0-9])(?=.*[!%,.;:])|(?=.*[A-Z])(?=.*[0-9])(?=.*[!%,.;:])$" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
Here i want to restrict new user password with few conditions::
Password strength:
- 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, !, $, #, %)
- - password Not contain the user's account name
As you can see there is passwordStrengthRegularExpression attribute i used in web.config section to match 1st condition( that Membership provide).
Need solution to achieve second condition.
In short:: I need to customize membership to match condition(character complexity enforced. ie:password Not contain the user's account name)
Updated::
I did what Eranga suggested me in my application . Now i also want to Display appropriate message when Membership createUser fails(on several customized condition).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以从默认提供程序进行子类化并处理 ValidatingPassword 事件。如果验证不符合您的第二个条件,您可以在此处取消验证。
您的
Web.Config
文件应包含以下内容。确保为type
属性提供自定义会员资格类别的全名。You can sub class from your default provider and handle the ValidatingPassword event. There you can cancel the validation if it does not meet your second criteria.
Your
Web.Config
file should include the following. Make sure you give the full name of your custom membership class for thetype
attribute.它不是 MVC,但您可以查看这个覆盖静态事件的示例。另外,由于这基本上与您之前问过的问题相同,所以有更多细节,也许您可以更新原来的问题?
It's not MVC, but you can look at this example of overriding the static event. Also, since this is basically the same question you asked before, with a little bit more detail, perhaps you could have just updated the original question?