Password Expires After 6 Months

pmgibs

New Member
Joined
Apr 5, 2017
Messages
16
I have a User Form that appears when the workbook opens asking for Username and Password and I would like the program to check if the password was created greater 6 months ago, if so require the user to change to password. However, it would need to be a new password, not just putting in their old password to reset the date. The below code works for simply checking the username (Column A) and password (Column B) match on the worksheet (Admin) and then allow the user to proceed in using the workbook, I am having difficulties implementing the password expiration to it.

Thanks in advance for any help!

VBA Code:
Private Sub Login_CommandButton_Click()
Dim LoginUser As Range
Dim FirstLoginUserAddress As String
Dim SuccessfulLogin As Boolean

    If Username_TB.Value <> "" And Password_TB.Value <> "" Then
        With Admin.Range("A:A")
            Set LoginUser = .Find(Username_TB.Value)
            SuccessfulLogin = False
            If Not LoginUser Is Nothing Then
                FirstLoginUserAddress = LoginUser.Address
                Do
                    If CStr(LoginUser.Offset(0, 1).Value2) = Password_TB.Value Then
                        SuccessfulLogin = True
                        Exit Do
                    
                    Else
                        Set LoginUser = .FindNext(LoginUser)
                    End If
                    Loop Until LoginUser Is Nothing Or LoginUser.Address = FirstLoginUserAddress
            End If
    
        End With

        If SuccessfulLogin = True Then
            Unload Me
            MsgBox ("Welcome!"), vbOKOnly
            UserForm3.Show
        Else
            MsgBox ("Invalid username or password!"), vbOKOnly
            Username_TB.Value = ""
            Password_TB.Value = ""
            Username_TB.SetFocus
        End If
    Else
        MsgBox "Enter the " & IIf(Username_TB.Value = vbNullString, "username", "password"), vbOKOnly
    End If

End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
All that looks overly complicated to me - stuff like getting ranges instead of just their values, Value2 and such.

First step should be just to find the user then offset and compare the dates. If required, msgbox and either exit or provide a means to update the password. I'm not seeing any of that. Also, if you posted where the date that is stored when a password is created then I missed it. You probably should clarify whether or not a past password can be used or not. You only say it can't be the same this time. If not, you need a running list.

Given the ease at which coded protection in Excel can be circumvented it seems to me like an exercise with not much payback, but that's just my opinion.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top