Guest User

Untitled

a guest
Apr 7th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. protected void Button1_Click(object sender, EventArgs e)
  2. {
  3. String CS = ConfigurationManager.ConnectionStrings["StegoDatabaseConnectionString1"].ConnectionString;
  4. using (SqlConnection con = new SqlConnection(CS))
  5. {
  6. //SqlCommand cmd = new SqlCommand("select * from userInfo where UserName='" + UserName.Text + "' and Password='" + Password.Text + "'", con);
  7. SqlCommand cmd = new SqlCommand("select * from userInfo where UserName = @username '" + "' and Password = @password'" + "'", con);
  8. cmd.Parameters.AddWithValue("@username ", UserName.Text); //SQL injetion Protection
  9. cmd.Parameters.AddWithValue("@password ", Password.Text); //SQL injection protection
  10. con.Open();
  11. SqlDataAdapter sda = new SqlDataAdapter(cmd);
  12. DataTable dt = new DataTable();
  13. sda.Fill(dt);
  14.  
  15. if (dt.Rows.Count != 0)
  16. {
  17. Button1.PostBackUrl = "HomePage.aspx";
  18.  
  19. }
  20. else
  21. {
  22. LabelError.Text = "Invalid Username or Password ! ";
  23.  
  24. }
  25. }
  26.  
  27. }
Add Comment
Please, Sign In to add comment