【问题标题】:How can I set maxInvalidPasswordAttempts for a particular user role如何为特定用户角色设置 maxInvalidPasswordAttempts
【发布时间】:2011-07-19 20:15:20
【问题描述】:

在我的应用程序中有不同的用户角色,例如管理员、用户、超级用户。我在我的应用程序中使用 ASP .net 成员资格提供程序。在我的 machine.config 文件中,maxInvalidPasswordAttempts 设置为 5,这是所有用户的默认值。我的问题是,即使对于管理员用户,最大无效密码尝试次数也是 5。我只需要更改管理员用户的最大无效密码尝试次数。请帮忙。

【问题讨论】:

    标签: c# asp.net forms-authentication


    【解决方案1】:

    我认为使用默认提供程序是不可能的。据我所知,由于MaxInvalidPasswordAttempts 甚至没有保存在数据库中。您可能需要考虑编写一个派生的 Membership 提供程序来实现这个附加层。

    public class myMembershipProvider : System.Web.Security.SqlMembershipProvider
    {
    
    public override int MaxInvalidPasswordAttempts
    {
        get
        {
            //Check to the role of the user....and pass back the attempts allowed for them
    
            if (HttpContext.Current.User.IsInRole(Admin))
            {
                return 9999; whatever...
            }
            return base.MaxInvalidPasswordAttempts;
        }
    }
    }
    

    【讨论】:

    • 我在我的应用程序中使用 .net 登录控件。请说明如何使用此方法。
    • @user.net 您应该能够创建此类,然后在 web.config 中将其定义为您的 MembershipProvider。将 type="System.Web.Security.SqlMembershipProvider" 替换为您的新自定义成员资格提供商的完全限定名称。
    猜你喜欢
    • 2019-07-20
    • 1970-01-01
    • 2022-01-22
    • 2020-07-30
    • 2017-10-07
    • 2019-04-24
    • 2018-12-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多