title: How to block a user after a specified failed attempts and unblocking the user after 5 minutes
body: <p>I would like to ask how do I block a user after a specified failed attempts. After 30 minutes or whatever time, the user will be able to log in again.. Here's my sample code for log in.</p>
  
  <pre><code>public partial class Login : System.Web.UI.Page
  {
      SimplerAES AES = new SimplerAES();
      protected void Page_Load(object sender, EventArgs e)
      {
          Session.Clear();
      }
      protected void btnLogIn_Click(object sender, EventArgs e)
      {
  
          if (txtUsername.Text == "" || txtPassword.Text == "")
          {
              lblMessage.Visible = true;
              txtUsername.Text = "";
              txtPassword.Text = "";
              lblMessage.Text = "Invalid Username/Password";
          }
          else
          {
              SqlConnection con = new SqlConnection(SeiboLMS.Helper.GetConnectionString());
              con.Open();
  
              SqlCommand com = new SqlCommand();
              com.Connection = con;
              com.CommandType = CommandType.Text;
  
              com.CommandText = "SELECT * FROM Users WHERE UserName=@UserName";
  
              com.Parameters.Add("@UserName", SqlDbType.NVarChar);
              com.Parameters[0].Value = txtUsername.Text;
  
              SqlDataReader data = com.ExecuteReader();
  
              if (data != null)
              {
                  while (data.Read())
                  {
                      if (txtPassword.Text == AES.Decrypt(data["Password"].ToString()))
                      {
                          if (data["UserTypeID"].ToString() == "1")
                          {
                              Session["userid"] = data["UserID"].ToString();
                              Session["usertypeid"] = data["UserTypeID"].ToString();
                              Session["username"] = data["UserName"].ToString();
                              Session["password"] = data["Password"].ToString();
                              Helper.Logs(int.Parse(data["UserID"].ToString()), 1, "Log In Successful");
                              Response.Redirect("Admin/Default.aspx");
                          }
                          else
                          {
                              Session["userid"] = data["UserID"].ToString();
                              Session["usertypeid"] = data["UserTypeID"].ToString();
                              Session["username"] = data["UserName"].ToString();
                              Session["password"] = data["Password"].ToString();
                              Helper.Logs(int.Parse(data["UserID"].ToString()), 1, "Log In Successful");
                              Response.Redirect("Employees/Default.aspx");
                          }
  
                      }
                      else
                      {
                          lblMessage.Text = "Invalid Username/Password.";
                          txtUsername.Text = "";
                          txtPassword.Text = "";
                      }
                  }
              }
              else
              {
                  lblMessage.Text = "Invalid Username/Password.";
                  txtUsername.Text = "";
                  txtPassword.Text = "";
              }
  
              data.Close();
              con.Close();
              con.Dispose();
          }
      }
  }
  </code></pre>
  
  <p>Please share with me what ideas do you have there. 
  Thank you in advance..</p>