【发布时间】:2013-11-25 00:08:50
【问题描述】:
我对 C# 完全陌生。我正在验证用户名和密码,区分大小写 来自数据库 sql server 2008。这是我的登录代码;我该怎么办?
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=db_WiBo;Integrated Security=True");
SqlCommand cmd = new SqlCommand("SELECT * from tb_Account where Username= '"+textBox1.Text+"' AND Password= '"+textBox2.Text+"' ", conn);
conn.Open();
SqlDataReader reader = cmd.ExecuteReader()
if (reader.HasRows)
{
reader.Close();
this.Hide();
}
提前致谢
【问题讨论】:
-
您的
SqlCommand有一个SQL Injection vulnerability。您似乎也以纯文本形式存储密码,这不好。 -
您应该做的第一件事是通过使用参数化查询来消除较大的 SQL 注入风险。第二件事可能是检查数据库字段/表上的排序规则以启用区分大小写...第三件事是在数据库中散列密码。
-
+哈希密码,不要存储...并使用好的哈希函数:throwingfire.com/storing-passwords-securely
标签: c# sql-server sqlcommand