简体   繁体   中英

Blocking a user after incorrect logins using Ajax timer control

i want to Block a user from login in for 5 minutes when he enters a wrong password.i am disabling the submit button for this by using timer control but i am confused as to how to enable the button after 5 minutes. if i enable it in the page load. the button gets enables after every post back or merely a refresh. here za screen shot of the code so far...

 protected void Button1_Click(object sender, EventArgs e)
{

    en.Log_Username = TextBox1.Text;
    en.Log_Password = TextBox2.Text;
    dt = new DataTable();
    dt = bll.log_Login(en);
    if (dt.Rows.Count > 0)
    {
        Session["emp_Mobile"] = en.Log_Password;
        Session["emp_Username"] = en.Log_Username;
        Response.Redirect("Calling.aspx");
        //Response.Redirect("Calling.aspx?emp_Mobile=" + Server.UrlEncode(en.Log_Password) + "&emp_Username=" + Server.UrlEncode(en.Log_Username));
    }
    else
    {
        Label1.Text = "Incorrect Username or Password";
        int count = 0;
        if (Session["incorrect"] != null)
        {
            count = Convert.ToInt32(Session["incorrect"]);
            Session["incorrect"] = count + 1;             
        }
        else
        {
            count = count + 1;
            Session["incorrect"] = count;
        }

        if (count >2)
        {
            Label1.Text = "You've Entered Wrong Password  3 times, Please wait for sometime!";
            Timer1_Tick(sender, e);


        }
    }
}
protected void Timer1_Tick(object sender, EventArgs e)
{
    Button1.Enabled = false;

}

you need to write some client side javascript to do that. javascript has a function setTimeout which can help. you can also look into using a cookie to record when was the last login attempt to prevent the page refresh situation.

still this is not a very good solution, if you want to enforce the rule you need to do it on the server as well. in your database record the time of the last unsuccessful login attempt and do not allow user to login before the desired time elapses.

Well, i had Removed

Button1.Enabled=true;

From Page_Load and the above code works fine blocking the user to log-in for 5 minutes by disabling the submit button.

just set the Interval="3000000" in asp:Timer Control.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM