c# - Blocking a user in ASP.NET using timeout -


i trying make login page using asp.net. want block user 5 minutes after 3 failed login attempts. didn't use login control in page,so guess can't use membership provider. want following:

  • set counter 0 , bool called accept_login true
  • every time validatepassword function returns 0,the counter increments
  • when counter's value 3, set accept_login on false,reset counter , start timeout 5 minutes

below code wrote without implementing these things. me integrate them? thanks!

    using system;     using system.collections.generic;     using system.linq;     using system.web;     using system.web.ui;     using system.web.ui.webcontrols;     using system.data.sqlclient;     using system.configuration;     using system.data;     using bcryptlibrary;     using system.web.security;      namespace bootstrapregisterlogin     {         public partial class login : system.web.ui.page         {             protected void page_load(object sender, eventargs e)             {              }              protected void button1_click(object sender, eventargs e)             {                  string cs = configurationmanager.connectionstrings["mydatabaseconectionstring1"].connectionstring;                 using (sqlconnection con = new sqlconnection(cs))                 {                      using (sqlcommand verifica = new sqlcommand())                     {                           con.open();                         verifica.commandtext = "select * [users] username=@nume_ut";                         verifica.parameters.add("@nume_ut", username.text);                         verifica.connection = con;                         verifica.executenonquery();                          using (sqldatareader rd = verifica.executereader())                         {                             while (rd.read())                             {                                 if (hasher.validatepassword(password.text, rd[2].tostring()))                                 {                                     con.close();                                     sqldataadapter sda = new sqldataadapter(verifica);                                     datatable dt = new datatable();                                     sda.fill(dt);                                      if (dt.rows.count != 0)                                     {                                          string utype;                                         utype = dt.rows[0][6].tostring().trim();                                                                           if (utype == "u")                                         {                                             session["username"] = username.text;                                             response.redirect("~/userhome.aspx");                                          }                                          if (utype == "a")                                         {                                             session["username"] = username.text;                                             response.redirect("~/adminhome.aspx");                                         }                                      }                                  }                                 else                                 {                                      lblerror.text = "username sau parola invalide";                                   }                                  }                              }                          }                     }                 }             }         } 


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -