简体   繁体   English

使用Ajax计时器控件错误登录后阻止用户

[英]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. 我想在用户输入错误的密码时阻止用户登录5分钟。我正在使用计时器控件来禁用此提交按钮,但是我对5分钟后如何启用按钮感到困惑。 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来做到这一点。 javascript has a function setTimeout which can help. javascript具有setTimeout函数可以提供帮助。 you can also look into using a cookie to record when was the last login attempt to prevent the page refresh situation. 您还可以考虑使用Cookie记录上一次登录尝试的时间,以防止页面刷新。

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. 在Page_Load和上面的代码中,可以通过禁用“提交”按钮很好地阻止用户登录5分钟。

just set the Interval="3000000" in asp:Timer Control. 只需在asp:Timer Control中设置Interval="3000000"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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