Hi,
I have a LogIn form that I use for my database and I just noticed a major flaw. Here is my code for what I use currently.
Code:
Private Sub LogIn_Click()
If IsNull(Me.txtUserName) Then
MsgBox "Please enter a User Name...", 16, "Missing User Name"
[txtUserName].SetFocus
Exit Sub
End If
If IsNull(Me.txtPassword) Then
MsgBox "Please enter a Password...", 16, "Missing Password"
[txtPassword].SetFocus
Exit Sub
End If
If Not StrComp(DLookup("Password", "tblUsers", "UserName = '" & txtUserName & "'"), txtPassword, 0) = 0 Then
MsgBox "Invalid User Name and/or Password. Try Again.", 16, "Invalid Attempt"
[txtPassword].SetFocus
Else
If txtUserName = "admin" Then
DoCmd.ShowAllRecords
DoCmd.Close acForm, "frmLogOn"
Else
DoCmd.OpenForm "frmMenu"
DoCmd.Close acForm, "frmLogOn"
DoCmd.ShowToolbar "Ribbon", acToolbarYes
End If
End If
End Sub
Here are a couple situations and the outcome of each.
1) Nothing entered, works perfectly
2) Just UserName entered, works perfectly
3) Just Password, works perfectly
4) UserName & Password entered correctly, works perfectly
5) UserName & Password entered, Password is entered incorrectly, works perfectly
6) UserName & Password entered incorrectly, it still lets me in. This is my problem, and it's a big one and I don't know how I didn't test for that before.
What do I need to do to fix this? I can't figure it out.
Thanks.