Results 1 to 8 of 8
  1. #1
    sgreenman is offline Novice
    Windows 10 Office 365
    Join Date
    May 2020
    Posts
    6

    Having Issues with Login Attempt incrementation

    I need help with this code that i am trying to use for login attempts. After i enter an invalid password it will not increment any further. The value for failed login attempts stays static. If anyone can help me with this it would be much appreciated i have been stuck on this for hours.



    Code:
    Option Compare Database
    
    
    Private Sub Login_Button_Click()
    
    Dim User, GetPass, Pass As String
    Dim Count, FailedAttempts As Integer
    
    Pass = Me.PasswordEntry_TextBox
    User = Me.UserNameEntry_TextBox
    GetPass = DLookup("UserPass", "UserList", "[UserName]='" & User & "'")
    Count = 2
    FailedAttempts = 1
    
    
    If (StrComp(Pass, GetPass, vbBinaryCompare) = 0) Then
        If MsgBox("Login was Successful. You will be redirected to the homepage after you click ok.", vbInformation, "Login Success") = vbOK Then
            DoCmd.OpenForm ("User_Homepage")
            DoCmd.Close acForm, "LoginPage", acSaveNo
            Exit Sub
        End If
        Else
            If (FailedAttempts = 3) Then
                If MsgBox("You have Exceeded the number of Login Attempts. Your account will now be locked. Reset your password using the Reset button on the login page or contact your system administrator.", vbInformation, "Account Locked") = vbOK Then
                'tbd
                Exit Sub
            End If
        Else
            If MsgBox("The Password you have entered is incorrect you have " & Count & " of 3 attempts left.", vbInformation, "Failed Login Attempt " & FailedAttempts & " of 3") = vbOK Then
                FailedAttempts = FailedAttempts + 1
                Count = Count - 1
            End If
        End If
    End If
    
    
    End Sub

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    In future, please post code between CODE tags to retain indentation and readability.

    Need a counter variable declared in module header so it will retain value between procedure calls.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    sgreenman is offline Novice
    Windows 10 Office 365
    Join Date
    May 2020
    Posts
    6
    Quote Originally Posted by June7 View Post
    In future, please post code between CODE tags to retain indentation and readability.

    Need a counter variable declared in module header so it will retain value between procedure calls.
    Im new to Posting and am not sure how to add CODE tags. Also how do i add it to a module header i am unsure what that even means to be completely honest.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    sgreenman is offline Novice
    Windows 10 Office 365
    Join Date
    May 2020
    Posts
    6
    I am wondering if my problem is that all of my forms code is under the Microsoft Access Class Objects because i have tried declaring public variable and am still getting errors. When i started creating the code for the button i just right clicked the button and selected build event. Which in turn put all of the VBA under a class object. I am pretty green when it comes to using access i have been dabbling for only about a month now.


  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    Code behind form is fine. Did you put variable in header of the form's module?

    If you want to provide db for analysis, follow instructions at bottom of my post.

    Have you learned debugging techniques? Review http://cpearson.com/excel/DebuggingVBA.aspx

    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    Code would be easer to read and follow with correct indentation. Consider:
    Code:
    Option Compare Database
    Option Explicit
    Private FailedAttempts As Integer
    
    
    Private Sub Command102_Click()
    Dim User As String, GetPass As String, Pass As String
    
    Pass = Me.PasswordEntry_TextBox
    User = Me.UserNameEntry_TextBox
    GetPass = DLookup("UserPass", "UserList", "[UserName]='" & User & "'")
    If (StrComp(Pass, GetPass, vbBinaryCompare) = 0) Then
        If MsgBox("Login was Successful. You will be redirected to the homepage after you click ok.", vbInformation, "Login Success") = vbOK Then
            DoCmd.OpenForm ("User_Homepage")
            DoCmd.Close acForm, "LoginPage", acSaveNo
            Exit Sub
        End If
    Else
        If (FailedAttempts = 3) Then
            If MsgBox("You have Exceeded the number of Login Attempts. Your account will now be locked. Reset your password using the Reset button on the login page or contact your system administrator.", vbInformation, "Account Locked") = vbOK Then
                'tbd
                FailedAttempts = 0
                Exit Sub
            End If
        Else
            FailedAttempts = FailedAttempts + 1
            MsgBox "The Password you have entered is incorrect you have " & 3 - FailedAttempts & " of 3 attempts left.", vbInformation, "Failed Login Attempt " & FailedAttempts & " of 3"
        End If
    End If
    End Sub
    Note that every variable must be explicitly declared or it will default to Variant type.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    sgreenman is offline Novice
    Windows 10 Office 365
    Join Date
    May 2020
    Posts
    6
    Thanks for all the help! I got it working finally i forgot to post an update. Thanks for all the helpful references as well.

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

Similar Threads

  1. First attempt at basic coding!
    By banno1 in forum Programming
    Replies: 4
    Last Post: 08-02-2018, 11:01 PM
  2. Replies: 4
    Last Post: 09-16-2015, 10:31 AM
  3. My First attempt at SQL
    By WhiskyLima in forum Misc
    Replies: 4
    Last Post: 04-08-2014, 09:54 AM
  4. Building my Own Collection(s) - Attempt #2!
    By Rawb in forum Programming
    Replies: 2
    Last Post: 12-18-2012, 08:25 AM
  5. Replies: 7
    Last Post: 08-10-2012, 03:09 PM

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