我想创建一个登录页面,但但我的登录按钮不起作用。我从我的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