Results 1 to 5 of 5
  1. #1
    Jimruns919 is offline Advanced Beginner
    Windows 10 Access 2019
    Join Date
    Jun 2023
    Location
    Pennsylvania
    Posts
    32

    Login Issue


    I created a form to have users log in. I was able to get everything to work except 1 thing.

    When a new user is created they are assigned a password of Password. If they use that password it brings them to a form to change the password and this all works.
    The problem I have is this, When they change the password, both the new password AND the temporary password will let them in and I cannot figure out why it does this.

    Code:
     Dim Userlevel As IntegerDim TempPass As String
    Dim ID As Integer
    Dim UserVarTemp As String
    'TempPass is for Temporaty Password given to the new user
    
    
    Me.PassTB = DLookup("Password", "Users_TBL", "Username='" & Me.Username.Value & "'")
    
    
        If IsNull(Me.Username) Then
            MsgBox "Please Enter a Valid Username!", vbInformation, "Username REQUIRED!"
            Me.Username.SetFocus
            
        ElseIf IsNull(Me.Password) Then
            MsgBox "Please Enter a Valid Password!", vbInformation, "Password REQUIRED!"
            Me.Password.SetFocus
            
            Else
                If (IsNull(DLookup("Username", "Users_TBL", "Username='" & Me.Username.Value & "'"))) Or _
                IsNull(DLookup("Password", "Users_TBL", "Password='" & Me.Password.Value & "'")) Then
                MsgBox "Username or Password is Incorrect!", vbCritical, "Login Denied!"
                Me.Username = ""
                Me.Password = ""
                Me.Username.SetFocus
                
                ElseIf StrComp(Me.PassTB, Me.Password, vbBinaryCompare) <> 0 Then
                        MsgBox "Password is Incorrect!", vbInformation, "Authentication Error!"
                        
            Else
                Userlevel = DLookup("[SecurityLevel]", "Users_TBL", "Username='" & Me.Username.Value & "'")
                TempPass = DLookup("[Password]", "Users_TBL", "Username='" & Me.Username.Value & "'")
                ID = DLookup("UserID", "Users_TBL", "Username='" & Me.Username.Value & "'")
                UserVarTemp = Me.Username
                    
                    If (TempPass = "Password") Then
                    DoCmd.OpenForm "ChangePassword_FRM", , , "[userid]=" & ID
                    
                    Else
                    If Userlevel < 15 Then
                    DoCmd.OpenForm "HFCAMainmenu_FRM"
                    Forms![HFCAMainMenu_FRM]!CurrentUserTB = UserVarTemp
                    
                        Else
                        MsgBox "You do not have Access to this area! Please contact the Systems Administrator for assistance.", vbInformation, "Not Authorized"
                        
                                   
            
                    End If
                    End If
                End If
        End If
                     
    End Sub
    Any assistance would be appreciated

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Suggest step through the code, your mixture of if’s,else’s and elseif’s is probably not doing what you think it is?

  3. #3
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Code:
    Sub flibble()
    
        Dim Userlevel As Integer
        Dim TempPass As String
        Dim ID As Integer
        Dim UserVarTemp As String
        'TempPass is for Temporaty Password given to the new user
        Me.PassTB = DLookup("Password", "Users_TBL", "Username='" & Me.UserName.value & "'")
        If IsNull(Me.UserName) Then
            MsgBox "Please Enter a Valid Username!", vbInformation, "Username REQUIRED!"
            Me.UserName.SetFocus
            
        ElseIf IsNull(Me.Password) Then
            MsgBox "Please Enter a Valid Password!", vbInformation, "Password REQUIRED!"
            Me.Password.SetFocus
            
        Else
            If (IsNull(DLookup("Username", "Users_TBL", "Username='" & Me.UserName.value & "'"))) Or _
                IsNull(DLookup("Password", "Users_TBL", "Password='" & Me.Password.value & "'")) Then
                MsgBox "Username or Password is Incorrect!", vbCritical, "Login Denied!"
                Me.UserName = ""
                Me.Password = ""
                Me.UserName.SetFocus
                
            ElseIf StrComp(Me.PassTB, Me.Password, vbBinaryCompare) <> 0 Then
                MsgBox "Password is Incorrect!", vbInformation, "Authentication Error!"
                        
            Else
                Userlevel = DLookup("[SecurityLevel]", "Users_TBL", "Username='" & Me.UserName.value & "'")
                TempPass = DLookup("[Password]", "Users_TBL", "Username='" & Me.UserName.value & "'")
                ID = DLookup("UserID", "Users_TBL", "Username='" & Me.UserName.value & "'")
                UserVarTemp = Me.UserName
                    
                If (TempPass = "Password") Then
                    DoCmd.OpenForm "ChangePassword_FRM", , , "[userid]=" & ID
                Else
                    If Userlevel < 15 Then
                        DoCmd.OpenForm "HFCAMainmenu_FRM"
                        Forms![HFCAMainMenu_FRM]!CurrentUserTB = UserVarTemp
                    Else
                        MsgBox "You do not have Access to this area! Please contact the Systems Administrator for assistance.", vbInformation, "Not Authorized"
                    End If
                End If
            End If
        End If
                     
    End Sub
    I've redone your indenting - I think it makes the issue more obvious...
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  4. #4
    Jimruns919 is offline Advanced Beginner
    Windows 10 Access 2019
    Join Date
    Jun 2023
    Location
    Pennsylvania
    Posts
    32
    This helped. Thank you! It came down to brackets [] around the word password where it was comparing the temp password and the actual.

  5. #5
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    You might consider removing some of your else/else if switches:
    Code:
     If IsNull(Me.UserName) Then
            MsgBox "Please Enter a Valid Username!", vbInformation, "Username REQUIRED!"
            Me.UserName.SetFocus
            
        ElseIf IsNull(Me.Password) Then
            MsgBox "Please Enter a Valid Password!", vbInformation, "Password REQUIRED!"
            Me.Password.SetFocus
           Else ....
    Could be replaced with
    Code:
     If IsNull(Me.UserName) Then
            MsgBox "Please Enter a Valid Username!", vbInformation, "Username REQUIRED!"
            Me.UserName.SetFocus
            Exit Sub
     End If        
     If IsNull(Me.Password) Then
            MsgBox "Please Enter a Valid Password!", vbInformation, "Password REQUIRED!"
            Me.Password.SetFocus
            Exit Sub 
     End If


    Which I think is much easier to read and follow.
    You then do similar with the rest of the code and remove the nesting to simplify it further.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Login Issue By Closing Access From Taskbar
    By data808 in forum Access
    Replies: 56
    Last Post: 01-23-2023, 08:06 PM
  2. Login issue
    By ocm in forum Forms
    Replies: 2
    Last Post: 10-19-2018, 05:55 AM
  3. Replies: 10
    Last Post: 03-27-2014, 03:58 PM
  4. Replies: 3
    Last Post: 03-17-2014, 10:23 AM
  5. Database Login Issue
    By Nosaj08 in forum Security
    Replies: 1
    Last Post: 07-13-2009, 10:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums