Password to expire after set period or by date

bptaw

Board Regular
Joined
Feb 27, 2017
Messages
69
Office Version
  1. 2016
Platform
  1. Windows
I have a user login form and I want the password to expire after a certain date. The workbook opens with a single page and the other sheets are made visible after successful login.
My sample user form login code is:

Private Sub cmdLogin_Click()

Dim user As String
Dim password As String
user = Me.txtUserID.Value
password = Me.txtPassword.Value

If (user = "admin" And password = "admin") Or (user = "user" And password = "user") Then

Unload Me
' Unhide all worksheets in the workbook
Worksheets("TS").Visible = xlSheetVisible
Worksheets("Hemp").Visible = xlSheetVisible
Worksheets("Maize").Visible = xlSheetVisible
Worksheets("Summary Page").Visible = xlSheetVisible
Worksheets("Water Calculations").Visible = xlSheetVisible

' Unhide a specific shape by name
Dim ws As Worksheet
Set ws = ActiveSheet ' Change to the desired worksheet
ws.Shapes("buttonLink").Visible = False
ws.Shapes("Pentagon 4").Visible = True
On Error GoTo 0 ' Reset error handling


Else

MsgBox "Invalid login credentials. Please try again."

End If

End Sub



Anyone help?
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Maybe something like this:
Rich (BB code):
user = Me.txtUserID.Value
password = Me.txtPassword.Value

If Date > DateValue("2023-10-15") Then
    MsgBox "something.."
    Exit Sub
End If

If (user = "admin" And password = "admin") Or (user = "user" And password = "user") Then

I want the password to expire after a certain date.
Edit:
Wait, do you mean you want to apply this only on certain passwords or all passwords?
 
Upvote 0
Solution
If Date > DateValue("2023-10-15") Then MsgBox "something.." Exit Sub End If
Maybe something like this:
Rich (BB code):
user = Me.txtUserID.Value
password = Me.txtPassword.Value

If Date > DateValue("2023-10-15") Then
    MsgBox "something.."
    Exit Sub
End If

If (user = "admin" And password = "admin") Or (user = "user" And password = "user") Then


Edit:
Wait, do you mean you want to apply this only on certain passwords or all passwords?
No, your simple solution does the trick. I think it is now pretty secure as I have also locked the vba. Am I right?
 
Upvote 0
Maybe something like this:
Rich (BB code):
user = Me.txtUserID.Value
password = Me.txtPassword.Value

If Date > DateValue("2023-10-15") Then
    MsgBox "something.."
    Exit Sub
End If

If (user = "admin" And password = "admin") Or (user = "user" And password = "user") Then


Edit:
Wait, do you mean you want to apply this only on certain passwords or all passwords?
But there is one other little matter. The shape I hide when the user logs in (ws.Shapes("buttonLink").Visible = False) shows up again on returning to that page. How can I stop that?
 
Upvote 0
But there is one other little matter. The shape I hide when the user logs in (ws.Shapes("buttonLink").Visible = False) shows up again on returning to that page. How can I stop that?
Sorry, I don't understand this part. But probably this:
Rich (BB code):
user = Me.txtUserID.Value
password = Me.txtPassword.Value

If Date > DateValue("2023-10-15") Then
    MsgBox "something.."
    Activesheet.Shapes("buttonLink").Visible = False
    Exit Sub
End If

If (user = "admin" And password = "admin") Or (user = "user" And password = "user") Then
 
Upvote 0
Sorry, I don't understand this part. But probably this:
Rich (BB code):
user = Me.txtUserID.Value
password = Me.txtPassword.Value

If Date > DateValue("2023-10-15") Then
    MsgBox "something.."
    Activesheet.Shapes("buttonLink").Visible = False
    Exit Sub
End If

If (user = "admin" And password = "admin") Or (user = "user" And password = "user") Then
I tried that but the button does not disappear. Effectively I want the button linked to the login form to be hidden after successful login. At the moment it is initially hidden but when I go back to the start sheet it's there again. The code I have is:
' Unhide a specific shape by name
Dim ws As Worksheet
Set ws = ActiveSheet ' Change to the desired worksheet
ws.Shapes("buttonLink").Visible = False
ws.Shapes("Pentagon 4").Visible = True
On Error GoTo 0 ' Reset error handling
after the sheets are made visible.
 
Upvote 0
I just need a way of making it stay hidden until I restart the workbook
 
Upvote 0
Maybe there's a way to hide this shape when other worksheets are visible?
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,958
Members
449,096
Latest member
Anshu121

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