How to specify # of failed login attempts for account lock in MVC 4 w/ default simplemembership provider

StackOverflow https://stackoverflow.com/questions/12848119

  •  06-07-2021
  •  | 
  •  

Question

How can you specify the # of failed logon attempts with the default simplemembership provider in ASP.NET MVC 4? I see there is an unlock account method but I don't see anywhere you can specify the # of failed attempts that cause the account to lock. If you were specifying it in MVC 3 you could specify maxInvalidPasswordAttempts in web.config under the provider. However, with MVC4 simplemembership you don't set up the provider in web.config.

Was it helpful?

Solution

It turns out simplemembership provider tracks the failed logins but it is up to you to catch the failed login attempts on user login with something like...

if(WebSecurity.IsAccountLockedOut(model.UserName,4,10000)){
                    return RedirectToAction("LockedAccount");
                }

Which of course leads to how to log them in once they reset their password. I chose to log them in directly in the password reset action. I could have put another field in the userprofile to track password being reset and bypass the check but figured it was not worth it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top