C# 登录页面asp.net无法工作
当打开登录页面时,它只显示用户名不正确,它似乎绕过了代码C# 登录页面asp.net无法工作,c#,asp.net,login,C#,Asp.net,Login,当打开登录页面时,它只显示用户名不正确,它似乎绕过了代码 SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["regConnectionString"].ConnectionString); conn.Open(); string checkuser = "select count(*) from users where username='" + usernametxt.Text + "'
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["regConnectionString"].ConnectionString);
conn.Open();
string checkuser = "select count(*) from users where username='" + usernametxt.Text + "'";
SqlCommand com = new SqlCommand(checkuser, conn);
int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
conn.Close();
if (temp == 1)
{
conn.Open();
string checkPasswordQuery = "select password from users where username = '" + usernametxt.Text + "'";
SqlCommand passComm = new SqlCommand(checkPasswordQuery, conn);
string password = passComm.ExecuteScalar().ToString().Replace(" ", "");
if(password == passwordtxt.Text)
{
Session["New"]= usernametxt.Text ;
Response.Write("password is correct");
}
else
{
Response.Write("password is not correct");
}
}
else
{
Response.Write("username is not correct");
}
根据您的代码片段,我建议的第一个选项是查看您传递的用户名的
users
表是否存在或有多个条目,因为如果(temp==1)
不满意
首先调试代码。您的问题到底是什么?调试代码时,
temp
的值是多少?你应该经常使用。这种类型的字符串连接对攻击是开放的。还可以使用using
语句来处理sql连接和命令。不要将密码存储为纯文本。阅读:我知道这只是一个大学项目,它不会上线,或者任何我在youtube上看教程的东西,我想这是0,你觉得呢?为什么不调试代码并查看?如果是0
你不认为总是显示用户名不正确是正常的吗
,因为0
不等于1
?我不太了解这一点,也不太明白教程上的代码是否将temp设置为一个值。我想做的是登录,我输入了正确的详细信息,所以它不应该说密码是正确的吗