Password Validation Issues (1 Viewer)

nika.duncan

Registered User.
Local time
Today, 02:17
Joined
Sep 23, 2013
Messages
10
Hi All,
I have a login form that is linked to three other forms - Manager, Supervisors, Staff and Admin. I uses a table with Access Level 1-4 and base on whichever level it opens the form. The problem I am having is that the if I enter an incorrect password it still opens the correct form. the code I've use is not checking the password, not sure where to correct. Please if anyone can assist I have attached the code below. This will be greatly appreciated.

Code:
Private Sub txtPassword_AfterUpdate()

Me.txtAccessLevel = Me.cboLogin.Column(3)
Me.txtPassword = Me.cboLogin.Column(1)

'Check that a user has been selected
If IsNull(Me.cboLogin) Then
    MsgBox "You need to select a user!", vbCritical
    Me.cboLogin.SetFocus

Else
   ' Check for correct password
   If Me.txtPassword = Me.cboLogin.Column(1) Then
        'Check if password needs to be reset
       ' If Me.cboLogin.Column(2) = True Then
       ' DoCmd.OpenForm "frmPasswordChange", , , "[UserLoginID] = " & Me.cboLogin
       ' DoCmd.OpenForm "frmPasswordChange", , , "[UserID] = " & Me.cboUser
        'Else
            
            If Me.txtAccessLevel = 1 Then
            DoCmd.OpenForm "frmAdminMode"
            Me.Visible = False
            Else

                If Me.txtAccessLevel = 2 Then
                    DoCmd.OpenForm "frmManagers"
                    Me.Visible = False
                Else

                    If Me.txtAccessLevel = 3 Then
                        DoCmd.OpenForm "frmSupervisors"
                        Me.Visible = False
                    Else

                        If Me.txtAccessLevel = 4 Then
                            DoCmd.OpenForm "frmStaff"
                            Me.Visible = False
                        Else

                            MsgBox "Password does not match, please re-enter!", vboOkOnly
                            Me.txtPassword = Null
                            Me.txtPassword.SetFocus
                        End If
                   End If
                End If
          End If

  End If

  End If
 ' End If


End Sub
 

Mihail

Registered User.
Local time
Today, 12:17
Joined
Jan 22, 2011
Messages
2,373
Divide et impera.
Code:
Private Sub txtPassword_AfterUpdate()

    Me.txtAccessLevel = Me.cboLogin.Column(3)
    Me.txtPassword = Me.cboLogin.Column(1)
    
    'Check that a user has been selected
    If IsNull(Me.cboLogin) Then
        MsgBox "You need to select a user!", vbCritical
        Me.cboLogin.SetFocus
Exit Sub
    End If

   ' Check for correct password
   If Me.txtPassword <> Me.cboLogin.Column(1) Then
        MsgBox "Password does not match, please re-enter!", vboOkOnly
        Me.txtPassword = Null
        Me.txtPassword.SetFocus
Exit Sub
    End If
            
    If Me.txtAccessLevel = 1 Then
        DoCmd.OpenForm "frmAdminMode"
        Me.Visible = False
Exit Sub
    End If
    
    If Me.txtAccessLevel = 2 Then
        DoCmd.OpenForm "frmManagers"
        Me.Visible = False
Exit Sub
    End If

    If Me.txtAccessLevel = 3 Then
        DoCmd.OpenForm "frmSupervisors"
        Me.Visible = False
Exit Sub
    End If

    If Me.txtAccessLevel = 4 Then
        DoCmd.OpenForm "frmStaff"
        Me.Visible = False
Exit Sub
    End If

End Sub

If still not work, it is (at least) a lot easier to debug.
 

nika.duncan

Registered User.
Local time
Today, 02:17
Joined
Sep 23, 2013
Messages
10
Thanks for your help I used the code and was able to debug and selected the correct field for the debug. I have included the code below for anyone else with similar problems.
Code:
Private Sub txtPassword_AfterUpdate()

Me.txtAccessLevel = Me.cboLogin.Column(3)


'Check that a user has been selected
If IsNull(Me.cboLogin) Then
    MsgBox "You need to select a user!", vbCritical
    Me.cboLogin.SetFocus
    
Exit Sub
End If

   
   ' Check for correct password
   If Me.txtPassword <> Me.UserPassword Then
        MsgBox "Password does not match, please re-enter!", vbOKOnly
        Me.txtPassword = Null
        Me.txtPassword.SetFocus
Exit Sub
    End If
    
        
        'Check if password needs to be reset
       ' If Me.cboLogin.Column(2) = True Then
       ' DoCmd.OpenForm "frmPasswordChange", , , "[UserLoginID] = " & Me.cboLogin
       ' DoCmd.OpenForm "frmPasswordChange", , , "[UserID] = " & Me.cboUser
        'Else
            
            If Me.txtAccessLevel = 1 Then
            DoCmd.OpenForm "frmAdminMode"
            Me.Visible = False
         Exit Sub
         End If
         

                If Me.txtAccessLevel = 2 Then
                    DoCmd.OpenForm "frmManagers"
                    Me.Visible = False
         Exit Sub
         End If
         
         '       Else

                    If Me.txtAccessLevel = 3 Then
                        DoCmd.OpenForm "frmSupervisors"
                        Me.Visible = False
          Exit Sub
          End If
          
          '          Else

                        If Me.txtAccessLevel = 4 Then
                            DoCmd.OpenForm "frmStaff"
                            Me.Visible = False
            Exit Sub
            End If
            
'Else

'                            MsgBox "Password does not match, please re-enter!", vboOkOnly
'                            Me.txtPassword = Null
'                            Me.txtPassword.SetFocus
                        
                


End Sub
 

Mihail

Registered User.
Local time
Today, 12:17
Joined
Jan 22, 2011
Messages
2,373
Glad to help you.

Only for your knowledge, the code (your last code) can be (again) condensed, so, much easier to debug and to maintain.
Code:
Private Sub txtPassword_AfterUpdate()
    'Check that a user has been selected
    If IsNull(Me.cboLogin) Then
        MsgBox "You need to select a user!", vbCritical
        Me.cboLogin.SetFocus
Exit Sub
    End If

   ' Check for correct password
   If Me.txtPassword <> Me.UserPassword Then
        MsgBox "Password does not match, please re-enter!", vbOKOnly
        Me.txtPassword = Null
        Me.txtPassword.SetFocus
Exit Sub
    End If
    
    Select Case Me.cboLogin.Column(3)
        Case 1
            DoCmd.OpenForm "frmAdminMode"
        Case 2
            DoCmd.OpenForm "frmManagers"
        Case 3
            DoCmd.OpenForm "frmSupervisors"
        Case 4
            DoCmd.OpenForm "frmStaff"
    End Select
    
    Me.Visible = False
End Sub
As you can see, the txtAccessLevel control is no more necessary.
Anyway, no one (except Robocap) can see that text box because the last statement Me.Visible = False.
 
Last edited:

Solo712

Registered User.
Local time
Today, 05:17
Joined
Oct 19, 2012
Messages
828
Hi All,
I have a login form that is linked to three other forms - Manager, Supervisors, Staff and Admin. I uses a table with Access Level 1-4 and base on whichever level it opens the form. The problem I am having is that the if I enter an incorrect password it still opens the correct form. the code I've use is not checking the password, not sure where to correct. Please if anyone can assist I have attached the code below. This will be greatly appreciated.

Code:
Private Sub txtPassword_AfterUpdate()
 
[COLOR=black]Me.txtAccessLevel = Me.cboLogin.Column(3[/COLOR])
[COLOR=red]Me.txtPassword = Me.cboLogin.Column(1)[/COLOR]
 
'Check that a user has been selected
If IsNull(Me.cboLogin) Then
    MsgBox "You need to select a user!", vbCritical
    Me.cboLogin.SetFocus
 
Else
   ' Check for correct password
  [COLOR=red] If Me.txtPassword = Me.cboLogin.Column(1) Then[/COLOR]
        'Check if password needs to be reset
       ' If Me.cboLogin.Column(2) = True Then
       ' DoCmd.OpenForm "frmPasswordChange", , , "[UserLoginID] = " & Me.cboLogin
       ' DoCmd.OpenForm "frmPasswordChange", , , "[UserID] = " & Me.cboUser
        'Else
 
            If Me.txtAccessLevel = 1 Then
            DoCmd.OpenForm "frmAdminMode"
            Me.Visible = False
            Else
 
                If Me.txtAccessLevel = 2 Then
                    DoCmd.OpenForm "frmManagers"
                    Me.Visible = False
                Else
 
                    If Me.txtAccessLevel = 3 Then
                        DoCmd.OpenForm "frmSupervisors"
                        Me.Visible = False
                    Else
 
                        If Me.txtAccessLevel = 4 Then
                            DoCmd.OpenForm "frmStaff"
                            Me.Visible = False
                        Else
 
                            MsgBox "Password does not match, please re-enter!", vboOkOnly
                            Me.txtPassword = Null
                            Me.txtPassword.SetFocus
                        End If
                   End If
                End If
          End If
 
  End If
 
  End If
 ' End If
 
 
End Sub

You are assigning the password to txt.Password from cbo.Login.Column(1) and then testing if they are the same. Of course, they will be the same no matter what you enter for password.

Best,
J.
 

Users who are viewing this thread

Top Bottom