1

Hi i want my login to be case sensitive but it is not so, and i don't know how to fix it. Here is my code:

 Private Sub btn_login_Click_1(sender As Object, e As EventArgs) Handles btn_login.Click
    Dim username, password As String
    Dim message As String = "The username or password was incorrect, please try again"
    username = txt_username.Text
    password = txt_password.Text

    If Me.UsernamesTableAdapter1.ScalarQueryLogin(username, password) And txt_username.Text = "admin" Then
        Form2.Show()
        txt_username.Text = ""
        txt_password.Text = ""
        System.Media.SystemSounds.Asterisk.Play()
        MessageBox.Show("Successfully logged in as Admin", "Welcome", MessageBoxButtons.OK, MessageBoxIcon.Information)

    ElseIf Me.UsernamesTableAdapter1.ScalarQueryLogin(username, password) Then
        Form2.Show()
        txt_username.Text = ""
        txt_password.Text = ""
        System.Media.SystemSounds.Asterisk.Play()
        MessageBox.Show("Successfully logged in as User", "Welcome", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Else
        System.Media.SystemSounds.Exclamation.Play()
        MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        txt_username.Text = ""
        txt_password.Text = ""
    End If
End Sub

Here is my ScalarQuery

SELECT * FROM Usernames Where Username = ? AND Password = ?
braX
  • 11,506
  • 5
  • 20
  • 33
Sasjumb
  • 83
  • 5
  • 2
    Don't store your passwords that way. Anyone can open an access DB (even password-protected databases are trivial to unlock) and see the entire contents of the UserNames table. You need to HASH the password values. This has the nice side-effect of also fixing the case sensitivity issue. – Joel Coehoorn Apr 03 '18 at 14:20
  • Possible duplicate of [username and password verification vb.net](https://stackoverflow.com/questions/47713267/username-and-password-verification-vb-net) – Andrew Morton Apr 03 '18 at 17:14

1 Answers1

2

Access is case-insensitive by default.

You can use StrComp in Access to do a binary compare, but it will be slower. Change your SQL to this:

SELECT * FROM Usernames Where Username = ? AND StrComp([Password], ?, 0) = 0
Erik A
  • 31,639
  • 12
  • 42
  • 67
  • Thank you this worked, you're a lifesaver. I have made StrComp also check username using same method as you showed me. – Sasjumb Apr 03 '18 at 13:47
  • SELECT * FROM Usernames Where StrComp([Username], ?, 0) = 0 AND StrComp([Password], ?, 0) = 0 – Sasjumb Apr 03 '18 at 13:47