Click here to Skip to main content
15,741,692 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating a new application..I created a login page successfully..Now I need to modify the login page ..Only 3 attempts only allowed for a user ..If the user wrongly enters the password more than 3 times(within 5 min) his account must be blocked..And error message must be shown as You cant access your page.

i have tired many sites coding but not use please help me any one

Try this,
public DateTime GetDt
    get {
        if (ViewState["GetDT"] == null)
            ViewState["GetDT"] = DateTime.Now;
        return (DateTime)ViewState["GetDT"]; }
    set { ViewState["GetDT"] = value; }
public int CNT
        if (ViewState["CNT"] == null)
            ViewState["CNT"] = 0;
        return (int)ViewState["CNT"]; }
    set { ViewState["CNT"] = value; }

protected void uxLogin_Click(object sender, EventArgs e)
    SqlDataAdapter ad = new SqlDataAdapter("select 1 from x where Uname='" + uxTxtUserName.Text.Trim()+ "' and PassWord='"+uxTxtPassword.Text.Trim()+"'", con);
    DataTable dt = new DataTable();
    if (dt.Rows.Count <= 0)
        CNT = Convert.ToInt32(CNT) + 1;
        TimeSpan tm = DateTime.Now - GetDt;
        if (CNT > 3 && tm.Minutes < 5)
            //Write code to show error msg.
        CNT = 0;
        GetDt = DateTime.Now;
Share this answer
Then think of your own logic and try to implement it.

For example, my logic would be...

1. Take one HiddenField or use View State.

2. On click of login button,
-> update value to this HiddenField or View State.
-> check whether the value contained in the above field exceeds 3.
-> if attempt value exceeds 3, then update one field in user table like "IsBlocked" to true.

4. Block user and show error message.

On login click, first go to user table with the username and check his "IsBlocked" status. And if it is false, then go for password checking and logging, otherwise show message that "Your account is blocked".

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900