Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in database - table logn (name varchar,username varchar,pasword varchar,locked char)
C#
protected void Button1_Click(object sender, EventArgs e)
    {
        SqlCommand cmd = new SqlCommand("select count(*) from logn where username=@username",con);
        cmd.Parameters.AddWithValue("@username",TextBox1.Text);
        con.Open();
        int userexist =  (int)cmd.ExecuteScalar();


        SqlCommand cmd1 = new SqlCommand("select count(*) from logn where pasword=@password", con);
        cmd1.Parameters.AddWithValue("@password", TextBox1.Text);
        int correctpass = (int)cmd1.ExecuteScalar();


        SqlCommand cmdlogin = new SqlCommand("select username,pasword,locked from logn where username=@usernam and pasword=@password", con);
      
        cmdlogin.Parameters.AddWithValue("@usernam", TextBox1.Text);
        cmdlogin.Parameters.AddWithValue("@password", TextBox2.Text);
        SqlDataReader dr = cmdlogin.ExecuteReader();
    
        while(dr.Read())
        {
            if ((char)dr[2] != 't')
            {
                Session["active"] = 't';
                Response.Redirect("page2.aspx");
            }
           
        }
        if(dr.Read()!=true)
        {
            if (userexist == 0)
            {
                Response.Write("<script>alert('user does not exist register yourself')</script>");
                Response.Redirect("Default.aspx");
            }
            else if(userexist==1 && correctpass==0)
            {
                Response.Write("<script>alert('invalid password')</script>");
                TextBox2.Text = "";
                TextBox2.Focus();
                Session["lock"] = ((int)Session["lock"] + 1);
            }

            if((int)Session["lock"]>3)
            {
                SqlCommand cmdupdate = new SqlCommand("update logn set locked='t' where username='"+TextBox1.Text+"'",con);
                con.Open();
                cmdupdate.ExecuteNonQuery();
            }
           
        
        }
        con.Close();
Posted
Updated 1-Jun-14 2:05am
v2
Comments
[no name] 1-Jun-14 8:05am    
This is just a code dump. It is not a question or description of a problem.
Telstra 1-Jun-14 8:48am    
on which line you are facing error?
JITHU.P 1-Jun-14 10:06am    
while(dr.Read())
{
if ((char)dr[2] != 't')
Richard MacCutchan 1-Jun-14 8:49am    
This looks like you are storing passwords as clear text which is totally the wrong way to do it. Go and research the proper way to store encoded passwords and protect your system from hackers.
Kornfeld Eliyahu Peter 1-Jun-14 9:48am    
If you post it as an answer I'll give your 500000000...000000000 upvotes!

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