我的註冊應用程序似乎在我運行SQL注入時,任何人對我有任何快速修復建議,我真的不想改變一切,但爲了使它能夠運行我的第一個項目更新。我的WinForm得到一個SQL注入
string constring = "datasource=127.0.0.1;port=3306;username=root;password=welcome";
string Query = "insert into userdatabase.users (userid, email, passone, passtwo, lastname, firstname) values('" + this.userid_txt.Text + "','" + this.email_txt.Text + "','" + this.passone_txt.Text + "','" + this.passtwo_txt.Text + "','" + this.lastname_txt.Text + "','" + this.firstname_txt.Text + "') ;";
MySqlConnection conDataBase = new MySqlConnection(constring);
MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase);
MySqlDataReader myReader;
try
{
conDataBase.Open();
myReader = cmdDataBase.ExecuteReader();
MessageBox.Show("Welcome to iDSTEM!");
while (myReader.Read())
{
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
該錯誤提示:
你在我的SQL語法錯誤;檢查手冊...第1行
是,該代碼是容易SQL注入(對於任何涉及撇號的東西都只是一個很好的老式失敗)。所以解決。什麼是問題? –
此代碼的哪些部分導致SQL注入我研究的所有內容都涉及單個'標記,它們不會影響結果 – Bendlino
http://stackoverflow.com/a/3216248/2186023 – DrCopyPaste