我想創建一個登錄頁面,但但我的登錄按鈕不起作用。我從我的sql服務器數據庫中選擇用戶名和密碼。登錄屏幕使用asp.net和SQL Server
不幸的是,我得到一個錯誤
System.Data.SqlClient.SqlException:附近有語法錯誤'
第27行:下面
int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
代碼:
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ConnectionString);
con.Open();
string checkuser = "select * from tb_Login where Username='" + txtUsername.Text + "' and Password='" + txtPassword.Text + "' ";
SqlCommand com = new SqlCommand(checkuser, con);
int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
con.Close();
if (temp == 1)
{
con.Open();
string checkPass = "select Password from tb_Login where Username='" + txtUsername.Text + "'";
SqlCommand passCom = new SqlCommand(checkPass, con);
string password = passCom.ExecuteScalar().ToString().Replace(" ", "");
if (password == txtPassword.Text)
{
Session["New"] = txtUsername.Text;
Response.Write("Correct");
}
else
{
Response.Write("Not Correct");
}
}
else
{
Response.Write("Username not correct");
}
您在用戶名後面缺少'=',應使用參數化查詢。任何人都可以通過SQL注入登錄或更糟。密碼也不應以純文本形式存儲。 –
訪問您的應用程序的通用密碼是:''OR 1 == 1; - ' – David
而且密碼顯然是以純文本格式存儲的。 – TTT