I am trying to prevent sql injection: like 1=1 , etc. First time doing this and I'm not sure if I'm doing it right?
Here is the code: The connection string is there I just removed it for the purpose of this question.
public void btnSubmit_Click(object sender, EventArgs e)
{
String login = txtUser.Text;
String pass = txtPass.Text;
string connString = "";
SqlConnection conn = new SqlConnection(connString);
conn.Open();
SqlCommand cmd = new SqlCommand("Select Users,Pass from logintable where Users='" + txtUser.Text + "' and Pass='" + txtPass.Text + "'", conn);
cmd.Parameters.Add("@Users", SqlDbType.VarChar, 20).Value = login;
SqlDataReader dr=cmd.ExecuteReader();
if(dr.Read())
{
new Login().Show();
}
else
{
lblFail.Text="Invalid username or password";
}
}