Quantcast
Viewing all articles
Browse latest Browse all 12583

Block users that enter wrong login details 3 times for a certain amount of time C#

Hi I am trying to do a login form which when user enter wrong login details for 3 times is blocked for certain amount of time in windows form application. 

below is my sql code:

create procedure sp_usrLogin
@username varchar(50),
@password varchar(50)
as 
begin
	select count(*) from dbo.[Login] where username=@username and usrpassword=@password
end 

below is my code:


 	int count = 0;
            string cs = ConfigurationManager.ConnectionStrings["LoginDBCS"].ConnectionString;
            SqlConnection con = new SqlConnection(cs);
            SqlDataAdapter adap = new SqlDataAdapter("sp_usrLogin", con);
            adap.SelectCommand.CommandType = CommandType.StoredProcedure;
            adap.SelectCommand.Parameters.Add("@username", SqlDbType.VarChar);
            adap.SelectCommand.Parameters["@username"].Value = txt_username.Text;
            adap.SelectCommand.Parameters.Add("@password", SqlDbType.VarChar);
            adap.SelectCommand.Parameters["@password"].Value = txt_password.Text;

            DataTable dt = new DataTable();
            adap.Fill(dt);
            
            if (dt.Rows[0][0].ToString() == "1")
            {
                this.Hide();
                mainForm mf = new mainForm();
                mf.Show();
            }

            else
            {
                count += 1;
                {
                    if (count > 3)
                        Application.Exit();
                    MessageBox.Show("Your username and password do not match.Please try again.");
                }
            }



 i want to block users who enters login details  wrong for 3 times but i cannot figure out what should i do? if the user enter login details wrong for 3 times i want to replace Application.exit() code with code that will block user for certain amount of time.

plz help me.





Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>