2014-03-01 15 views
0

我想阻止用戶登錄進入5分鐘,當他輸入錯誤的密碼時,我通過使用計時器控件禁用了此提交按鈕,但我很困惑5分鐘後如何啓用按鈕。如果我在頁面加載中啓用它。該按鈕在每次回發或僅刷新後都會啓用。這裏z屏幕截圖的代碼迄今...使用Ajax計時器控件登錄錯誤後阻止用戶

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; 

} 
+0

請將您的代碼發佈爲文本 – VladL

+0

我通過從頁面加載中刪除Button1.Enabled來獲得它的工作。 唯一的事情是標籤現在不打印錯誤消息。 – Sunny

回答

0

好吧,我不得不刪除

Button1.Enabled=true; 

從Page_Load中 和上面的代碼工作正常,阻止通過禁用提交按鈕登錄,在5分鐘的用戶。

只需在asp:Timer Control中設置Interval="3000000"即可。

1

你需要寫一些客戶端JavaScript來做到這一點。 javascript有一個函數setTimeout可以提供幫助。您還可以使用Cookie來記錄上次登錄嘗試的時間,以防止頁面刷新情況。

這仍然不是一個很好的解決方案,如果你想強制執行規則,你也需要在服務器上執行它。在您的數據庫中記錄最後一次不成功的登錄嘗試的時間,並且不允許用戶在期望的時間過去之前登錄。

+0

謝謝你。我是一個新的發展中的東西...仍在學習:) – Sunny