Click here to Skip to main content
16,006,768 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to block user after 3 invalid attempts. and i've a table which contains 2 columns usernaem and password.
Posted

Rather than roll your own, you could always look at the membership services frameworks within .Net.

Alternatively,
Add an integer FailedLogin column, increment that each failed login, set to 0 on successful login.

Add a Boolean Locked column, if failed count exceeds your trigger level, set to true.

There are other ways of doing this, but that is probably the simplest.
 
Share this answer
 
Hi,
In below code I have explained the logic , how to implement that. If you need any clarifications do let me know.
C#
int NoOfLoginAttempt = 0;
       private void btnLogin_Click(object sender, EventArgs e)
       {
          //Get the User name & Password from the text box
           //Connect to database and get the user details
          if(FOUND )
          {
               if(Password is matched)
               {
                   if(NoOfLoginAttempt ==3)
                   {
                       //connect to database and set the blockFlag=true;
                       //Inform the user that, your account is blocked.
                   }
                   else
                   {

                       NoOfLoginAttempt++;
                       //Show message box to usr to re-enter the password again
                   }
               }
          }
       else
        {
           //show the message box "user not exist"
       }
   }


Best Regards
Muthuraja
 
Share this answer
 
Follow the answer Block user for 15 minutes after 5 login attempts[^], which suggests to use SqlMembershipProvider[^].

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