我正在VB.Net和MySQL数据库中使用,我想检查用户名和密码在数据库值上是否匹配示例:当用户输入小写字母“ a”且在数据库中输入大写字母时,Username = Admin11与Username = admin11不同“ 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

最佳答案

在查询中使用binary

SELECT COUNT(*)
FROM pos_db.tblusers
WHERE
  BINARY Username = @user
  AND BINARY Password = @pass

09-18 03:17
查看更多