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!
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