User Lockout in .net 4.5.1 ASP.NET MVC 5

醉酒当歌 提交于 2019-12-03 04:25:29

问题


So in the new .Net Framework 4.5.1 AspNetUser table does not have a column to lock user out after a finite number of unsuccessful attempts. Are there frameworks or solutions built for that purpose to replace the functionality that once existed in previous .net frameworks? Or do I have to build my own?


回答1:


In the upcoming 2.0 Identity release, there is support for Account Lockout

Configuration:

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

Usage:

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 


来源:https://stackoverflow.com/questions/22483316/user-lockout-in-net-4-5-1-asp-net-mvc-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!