Click here to Skip to main content
13,293,178 members (92,320 online)
Rate this:
Please Sign up or sign in to vote.
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
Posted 19-Feb-13 0:42am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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;
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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".


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171207.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100