用户锁定.net 4.5.1 ASP.NET MVC 5

cSh*_*Guy 15 asp.net security asp.net-mvc asp.net-mvc-5 asp.net-identity

因此,在新的.Net Framework 4.5.1中,AspNetUser表没有用于在有限次数的不成功尝试后锁定用户的列.是否存在为此目的而构建的框架或解决方案,以替换曾经存在于以前的.net框架中的功能?或者我必须建立自己的?

Hao*_*ung 31

在即将发布的2.0 Identity版本中,支持Account Lockout

组态:

    manager.UserLockoutEnabledByDefault = true; // Enables ability to lockout for users when created
    manager.DefaultAccountLockoutTimeSpan = TimeSpan.FromMinutes(5);
    manager.MaxFailedAccessAttemptsBeforeLockout = 5;
Run Code Online (Sandbox Code Playgroud)

用法:

manager.IsLockedOutAsync(user.Id) // Check for lockout
manager.ResetAccessFailedCountAsync(user.Id); // Clear failed count after success
manager.AccessFailedAsync(user.Id); // Record a failure (this will lockout if enabled)
manager.SetLockoutEnabled(user.Id, enabled) // Enables or disables lockout for a user 
Run Code Online (Sandbox Code Playgroud)