【发布时间】:2021-12-28 08:12:01
【问题描述】:
这是我的代码 我不知道我的错是什么,但它没有检查用户名是否存在于数据库中。
String connectionString = @"Data Source=localhost; Database=pramod; User ID=itesuser; password=ites; Port=3309;";
MySqlConnection con = new MySqlConnection(connectionString);
con.Open();
String query = "select * from logins where USERNAME=@username and PASSWORD=@password";
MySqlCommand cmd = new MySqlCommand(query, con);
cmd.Parameters.AddWithValue("@username", TextBox1.Text.Trim());
cmd.Parameters.AddWithValue("@password", TextBox2.Text.Trim());
MySqlDataAdapter sda = new MySqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
int i = (int)cmd.ExecuteScalar();
if (i == 0)
{
Response.Write("username wrong");
}
if (dt.Rows.Count > 0)
{
Session["username"] = TextBox1.Text.Trim();
Response.Redirect("Dashboard.aspx");
}
else {
Label1.Visible = true;
Label1.Text = "Your password is incorrect";
Label1.ForeColor = System.Drawing.Color.Red;
}
con.Close();
正在检查密码是否正确但不是用户名,现在我需要检查用户名和密码
【问题讨论】:
-
您是否以纯文本形式存储密码?不要这样做,这是可怕的安全性!另外,如果用户名错误,不要告诉用户,只告诉他们登录失败。任何时候,只要您向用户提供比必要更多的详细信息,他们就有更多机会侵入您的代码。
-
这是我的任务,我必须显示用户名错误@DavidG
-
那你应该告诉你的老板这是个多么糟糕的主意。恐怕我不会帮助某人降低应用程序的安全性。祝你好运!
标签: c# asp.net asp.net-core authentication