Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
protected void btnLogin_Click(object sender, EventArgs e)
{
   SqlDataAdapter da = new SqlDataAdapter("select * from users where username='" + txtUserName.TemplateControl + "' and password='" + txtPswrd.Text + "'", con);
   DataSet ds = new DataSet();
   da.Fill(ds, "users");
   try
   {
      con.Open();
      da.Fill(ds);			
      if (ds.Tables[0].Rows.Count > 0)
         Response.Redirect("home.aspx");
      else
         Label1.Text = " wrong pswd";
   }
   catch (Exception err){}
}
Posted
Updated 10-Jan-13 10:57am
v2
Comments
[no name] 10-Jan-13 6:08am    
so, what we do for this...?
Rai Pawan 10-Jan-13 6:09am    
your query seems to have wrong username parameter value i.e., instead of txtUserName.TemplateControl you should be using txtUserName.Text
- Pawan
willempipi 10-Jan-13 6:14am    
Rai, why not post it as an answer?

Anyways Gilbertinino, this code will allow sql injection, use parameters to specify the email and password.
sarathsprakash 10-Jan-13 6:17am    
txtUserName.TemplateControl you should be using txtUserName.Text

your query seems to have wrong username parameter value i.e., instead of txtUserName.TemplateControl you should be using txtUserName.Text

Also please read on to see how to use sqlparameters as your current code can be a victim of sql injections.

Regards
Pawan
 
Share this answer
 
txtUserName.TemplateControl you should be using txtUserName.Text
 
Share this answer
 
You query should be like following

C#
SqlDataAdapter da = new SqlDataAdapter("select * from users where username='" + txtUserName.Text.Trim() + "' and password='" + txtPswrd.Text.Trim() + "'", con);


Note: Use parameterized query for better performance and security purpose
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