I have a login form that works really good except for one part of it. The security level works and the fact that I can create a new password if the first password I set it to is "password". However, there is one flaw that I don't seem to understand. If I have 5 users in my table that stores all the usernames and passwords, I will be able to use any of the 5 usernames with any of the 5 passwords listed. In other words it does not verify and match that the username and password must match together for the user to log in. The user can just use their username with any of the 5 passwords that are in this table. How do I change this code to make it work so that it will match up the username and passwords with each other before going any further in the database?
Private Sub cmdLogin_Click()
Dim UserLevel As Integer
Dim TempPass As String
Dim ID As Integer
If IsNull(Me.txtUsername) Then
MsgBox "Please Enter Username", vbInformation, "Username Required"
Me.txtUsername.SetFocus
ElseIf IsNull(Me.txtPassword) Then
MsgBox "Please Enter Password", vbInformation, "Password Required"
Me.txtPassword.SetFocus
Else
'process the job
If (IsNull(DLookup("Username", "tblUser", "Username='" & Me.txtUsername.Value & "'"))) Or _
(IsNull(DLookup("Password", "tblUser", "Password ='" & Me.txtPassword.Value & "'"))) Then
MsgBox "Incorrect Username Or Password"
Me.txtUsername.SetFocus
Else
UserLevel = DLookup("UserSecurity", "tblUser", "Username = '" & Me.txtUsername.Value & "'")
TempPass = DLookup("Password", "tblUser", "Username = '" & Me.txtUsername.Value & "'")
ID = DLookup("UserID", "tblUser", "Username = '" & Me.txtUsername.Value & "'")
DoCmd.Close
If (TempPass = "Password") Then
MsgBox "Please Change Password", vbInformation, "New Password Required!"
DoCmd.OpenForm "Change Password", , , "[UserID] = " & ID
Else
If UserLevel = 1 Then
DoCmd.OpenForm "Admin Main Menu", acNormal, , , acFormAdd
Else
DoCmd.OpenForm "LSTS Main Menu", acNormal, , , acFormAdd
End If
End If
End If
End If
End Sub