This code is for a login form I have setup to enter the front end copy of a database. In one database it works like a charm. I imported the form and corresponding objects to another database and it appears to be not recognizing my password when I enter it. I just keep getting the message box I have popping up that says, "Incorrect password". Any help figuring this out would be greatly apprecaited.

The SQL statement that drives the cboUser combo box on the login form is:

SELECT tblUser.UserID, [FName] & " " & [LName] AS Fullname, 
       tblUser.Password, tblUser.PWReset, tblUser.AccessLevelID 
FROM tblUser ORDER BY tblUser.LName, tblUser.FName;  

.

Private Sub OkBTN_Click()
    Static intIncorrectCount As Integer
    Dim AuthorityNumber As Integer
    'Dim rs         As Recordset
    
    'TempVars("Username") = Me.cboUser.Value
    
    'Column references for cbouser row source reference
    'UserID = 0
    'FullName = 1
    'Password = 2
    'PWReset = 3
    'AccessLevelID = 4
    
    'Set rs = CurrentDb.OpenRecordset("UserNameQuery", dbOpenSnapshot)
    
    'N = Nz(DLookup("Fullname", "UserNameQuery", "Fullname=""" & Me.cboUser & """"), " ")
    
    'Check that User is selected
    If IsNull(Me.cboUser) Then
        MsgBox "You forgot To Select your name from the drop down menu!", vbCritical
        Me.cboUser.SetFocus
    Else
        'Check for correct password
        If Me.txtPassword = Me.cboUser.Column(2) Then
            
            'Check if password needs to be reset
            If Me.cboUser.Column(3) Then
                DoCmd.OpenForm "frmPasswordChange", , , "[UserID] = " & Me.cboUser
            End If
            
            Me.Visible = FALSE
            intIncorrectCount = 0
            
            'Main menu after correct login based on AuthorityNumber
            If Me.cboUser.Column(4) = 5 Then
                DoCmd.OpenForm "SRL1MainMenu"
                'Forms!AMSReportForm!L2Menubtn.Visible = False
                Forms!SRL1MainMenu!FullNameLoggedIn = Forms!frmLogin!cboUser.Column(1)
            Else
                DoCmd.OpenForm "L2MainMenu2"
                'Forms!AMSReportForm!L2Menubtn.Visible = True
                Forms!L2MainMenu2!FullNameLoggedIn = Forms!frmLogin!cboUser.Column(1)
            End If
            
            'Failed login attempt limitation
        ElseIf intIncorrectCount > 1 Then
            MsgBox "Too many failed login attempts. Click OK To Set New password", vbOK + vbExclamation
            DoCmd.OpenForm "frmPasswordChange", , , "[UserID] = " & Me.cboUser
            'DoCmd.Close acForm, "frmLogin"
        Else
            MsgBox "Incorrect password", vbOKOnly + vbExclamation
            
            Me.txtPassword = Null
            Me.txtPassword.SetFocus
            intIncorrectCount = intIncorrectCount + 1
        End If
    End If
    
End Sub
1

There are 1 best solutions below

0
Gustav On

First, @Andre is probably right - you may have to apply brackets to "Password".

Next, this may not perform a case sensitive comparison:

If Me.txtPassword = Me.cboUser.Column(2) Then

Use StrComp to do that:

If StrComp(Me!txtPassword.Value, Me!cboUser.Column(2), vbBinaryCompare) = 0 Then

Finally, you should never store plain passwords; store a hash value instead. It isn't that difficult, if you study my latest article:

Storing passwords in VBA using the Microsoft NG Cryptography (CNG) API