title: Lock user after five failed login attempts and show an error in MVC3 Asp.net
body: <p>I want to show an error to the user after 5  failed login attempts and then lock her, I set this in web.config</p>
  
  <pre><code>  maxInvalidPasswordAttempts="5"
  </code></pre>
  
  <p>Now I want to check user login attemps in LogOn controller and send an error if this parameter is more than 5, How can I count user login attemps and check it?
  here is my controller:</p>
  
  <pre><code>    //
      // GET: /Account/LogOn
  
  
      public ActionResult LogOn()
      {
          return View();
      }
  
      //
      // POST: /Account/LogOn
  
  
      [HttpPost]
      public ActionResult LogOn(LogOnModel model, string returnUrl)
      {
          if (ModelState.IsValid)
          {
  
              if (Membership.ValidateUser(model.UserName, model.Password))
              {
  
                      FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                      if (Url.IsLocalUrl(returnUrl) &amp;&amp; returnUrl.Length &gt; 1 &amp;&amp; returnUrl.StartsWith("/")
                          &amp;&amp; !returnUrl.StartsWith("//") &amp;&amp; !returnUrl.StartsWith("/\\"))
                      {
                          return Redirect(returnUrl);
                      }
                      else
                      {
                          return RedirectToAction("Index", "Home");
                      }
                  }
                  else
                  {
                      ModelState.AddModelError("", "The user name or password provided is incorrect.");
                  }
          }
  
          // If we got this far, something failed, redisplay form
               return View(model);
         }
  </code></pre>