這是SQL注入證明嗎?或者至少可以嗎?我在網上得到這個,所以我真的可以使用一些幫助。我目前正在構建一個非常大的程序,如果我想讓它付費,我決定添加一個登錄頁面。請幫忙!是我的代碼SQL注入證明?
if (txt_UserName.Text == "" || txt_Password.Text == "")
{
MessageBox.Show("Please provide a Username and Password");
return;
}
try
{
// Create SqlConnection
SqlConnection con = new SqlConnection(cs);
SqlCommand cmd = new SqlCommand("Select * from tbl_Login where UserName = @username and Password = @password", con);
cmd.Parameters.AddWithValue("@username", txt_UserName.Text);
cmd.Parameters.AddWithValue("@password", txt_Password.Text);
con.Open();
SqlDataAdapter adapt = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapt.Fill(ds);
con.Close();
int count = ds.Tables[0].Rows.Count;
// If count is equal to 1, than show frmMain form
if (count == 1)
不是。您應該使用準備好的語句。在SqlConnector文檔中閱讀它。我正在使用手機,所以現在無法發佈完整答案。 – SplittyDev
@SplittyDev與此相比,準備好的聲明如何提供任何保護?這是一樣的,但準備,在這種情況下,甚至可能沒有用。 –
注意:使用DataSet進行這種查詢非常糟糕。他們速度慢,內存不足,你會更好地使用'DataReader' –