【问题标题】:What is the best way to keep the User's Lockout status in ApplicationUser?在 ApplicationUser 中保持用户锁定状态的最佳方法是什么?
【发布时间】:2020-09-06 21:52:23
【问题描述】:

我想在 Asp.Net Mvc(Core 或 NetFramework)中的我的 ApplicationUser(继承自 IdentityUser)中保存用户的锁定状态,那么从设计角度来看,哪个实现更好?

1. 分别具有 IsActive 属性和 LockoutReason 枚举属性的用户

class ApplicationUser: IdentityUser
{
    // ...
    public bool IsAcitve {get;  set;}
    public UserLockoutReason LockoutReason {get; set; }
}

enum UserLockoutReason 
{
    NotLocked,
    LockedByAdmin,
    MaximumWrongPasswordAttemptsReached,
    ...
}

2. 具有 ActiveStatus 枚举的用户

class ApplicationUser: IdentityUser
{
    // ...
    public UserActiveStatus ActiveStatus {get; set; }
}

enum UserActiveStatus
{
    Active,
    LockedByAdmin,
    MaximumWrongPasswordAttemptsReached,        
    ...
}

p.s:这个设计将成为我们 IdentityProvider 的 UserManagement 的一部分,所以对我们来说实现最好的方式非常重要

【问题讨论】:

    标签: c# asp.net-mvc asp.net-core-mvc asp.net-identity


    【解决方案1】:

    我会朝这个方向走:

    class ApplicationUser: IdentityUser
    {
        // ...
        public UserActiveStatus ActiveStatus {get; set; }
    }
    
    enum UserActiveStatus
    {
        Active,
        LockedByAdmin,
        MaximumWrongPasswordAttemptsReached,        
        ...
    }
    
    

    由于ActiveStatus 是您需要为用户提供的最终信息,因此需要在 if-else 语句中对user.IsActive 进行分支,然后获取LockoutReason 以防帐户被锁定”没必要

    【讨论】:

    • 好的,但是我怎样才能保持用户的解锁状态,更新?
    • 我(AspNet 身份)在 3 次错误密码尝试后锁定了用户(John Doe)。 3 小时后他/她回来并再次登录,他/她是有效的登录,我会将他的 ActiveStatus 更新为“活动”。但是如果他在接下来的 10 小时内不会回到系统,我如何在 3 小时后将他的 ActiveStatus 更新为“活动”?
    猜你喜欢
    • 2015-04-28
    • 2012-01-08
    • 1970-01-01
    • 2021-11-02
    • 2015-07-02
    • 1970-01-01
    • 2018-08-14
    相关资源
    最近更新 更多