I have been working on a project and I am very new to C#. I have Login which is correct but it is vulnerable to SQL injection attacks. Here is my code - can anybody help me out how to apply a stored procedure with parameters so it can be more secure?
protected void Button1_Click(object sender, EventArgs e)
{
string Cs = ConfigurationManager.ConnectionStrings["MyDatabase1ConnectionString"].ConnectionString;
using(SqlConnection con=new SqlConnection(Cs))
{
SqlCommand cmd = new SqlCommand("Select * from Users where Username= '" + Username.Text + "' And " +
"Password='" + Password.Text+ "'", con);
con.Open();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count != 0)
{
Response.Redirect("~/Cuhome.aspx");
}
else
{
LblError.Text = "Invalid Username & Password";
}
}
}
Thanks