我正在将VB.Net与MySQL数据库一起使用,我想检查用户名和密码是否与数据库值匹配示例:Username = Admin11 与Username = admin11 < / strong>,当用户输入小写字母“ a”,而在数据库中输入大写字母“ A”时,这是错误的。我想发生的是,当用户输入的用户名与数据库值中的用户名不完全相同时,用户名不正确,这是我的代码,但是不起作用
Dim con = New MySqlConnection
con.ConnectionString = "server=localhost;userid=root;password=alpine;port=3305;database=pos_db;pooling=false;SslMode=none"
con.Open()
Dim qry As String = "SELECT COUNT(*) FROM pos_db.tblusers WHERE Username=@user AND Password=@pass"
Dim cmd As New MySqlCommand(qry, con)
cmd.Parameters.AddWithValue("@user", txtUsername.Text)
cmd.Parameters.AddWithValue("@pass", txtPassword.Text)
Dim count As Integer = Convert.ToInt32(cmd.ExecuteScalar())
If count <> 0 Then
Me.Hide()
FrmSelect.Show()
Else
MessageBox.Show("Either username or password in incorrect", "System", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
答案 0 :(得分:0)
在查询中使用二进制`
从pos_db.tblusers中选择COUNT(*)个二进制用户名= @ user并且 BINARY Password = @ pass
`
答案 1 :(得分:0)
非常感谢@parkway先生为我提供的帮助,这是对我的问题的正确查询。现在,我学习编程方面的新知识,再次感谢先生。
con.Open()
Dim qry As String = "SELECT COUNT(*) FROM pos_db.tblusers WHERE BINARY Username=@user AND BINARY Password=@pass"
Dim cmd As New MySqlCommand(qry, con)
cmd.Parameters.AddWithValue("@user", txtUsername.Text)
cmd.Parameters.AddWithValue("@pass", txtPassword.Text)
Dim count As Integer = Convert.ToInt32(cmd.ExecuteScalar())
If count <> 0 Then
Me.Hide()
FrmSelect.Show()
Else
MessageBox.Show("Either username or password in incorrect", "System", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If