Please guy, can someone help me with the following:
How to restrict login from accessing my database application
one week after first login?
My login process is as follows:
i have a Table called Tbl_Users that holds username and password.
Tbl_Users
-------------
UserID (pk)
UserName,
Password,
FirstLoginDate
On my login form i have 1 combox to select username, and 1 text field to type password; then one button upon which user clicks to login.
I used the following vba to operates the login process:
Code:
Option Compare Database
Private intLogonAttempts As Integer
Private Sub CmdLogin_Click()
'Check to see if data is entered into the UserName combo box
If IsNull(Me.CboUsername) Or Me.CboUsername = "" Then
MsgBox "You must select a User name.", vbOKOnly, "Required Data"
Me.CboUsername.SetFocus
Exit Sub
End If
'Check to see if data is entered into the password box
If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txtPassword.SetFocus
Exit Sub
End If
'Check that value entered for password field matches whatever is inside Tbl_Users
If Me.txtPassword.Value = DLookup("Password", "tbl_Users", _
"[UserId]=" & Me.CboUsername.Value) Then
UserID = Me.CboUsername.Value
'When all checkings are correct then display something...
MsgBox "Nice! You have successfully logged into the system", vbOKOnly, "Required Data"
Else
'When checking fails then display error message
MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
"Invalid Entry!"
Me.txtPassword.SetFocus
End If
'When user types incorrect password 3 times database application will shutdown
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 2 Then
MsgBox "You do not have access to this database. Please contact the system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
Now, in order to solve my issue, i was thinking of the following logic:
1 - Automatically record the first login date of a user in the column FirstLoginDate of table Tbl_Users.
2 - Then perform some check on ActualDate and FirstLoginDate.
For example, upon clicking on the login button, perform the following check:
- if ActualDate > than lastLoginDate+7days then error message
- if ActualDate < than lastLoginDate+7days then show Main Menu
- if ActualDate = than lastLoginDate+7days then show Main Menu
Can someone help me apply the above logic (vba code)?
Or guide me toward more convenient way to restrict login from accessing my database application one week after first login?