Hi,
I am working on a log in form for an Access 2003 db. Because the built-in jet database engine doesn't supply the ability to record every log attempt, failed attempt, validate passwords, user lock after X failed log attempts, ... I desided to program one of my own.
The code itselves works fine but I cannot write the value of intLogonAttempt to tbl_users, I would like to lock the user after 3 failed log attempts, and made a field called [Attempts] into tbl_users, which count every faild log attempts and a field called [lock_user] as boolean to activate the user lock.
I can count with intlogAttempts but I cannot write the value to the tbl to use to count every failed log on attempt, it always goes back to zero and even with a macro It doesn't work.
My goal is to,create a complete log on record where the db will write every log on (failed or succesfull) to a record, as well as every change of password, new users, deactivated users,....
Help is greatly appriciated.
thanks,
Tom
I am working on a log in form for an Access 2003 db. Because the built-in jet database engine doesn't supply the ability to record every log attempt, failed attempt, validate passwords, user lock after X failed log attempts, ... I desided to program one of my own.
The code itselves works fine but I cannot write the value of intLogonAttempt to tbl_users, I would like to lock the user after 3 failed log attempts, and made a field called [Attempts] into tbl_users, which count every faild log attempts and a field called [lock_user] as boolean to activate the user lock.
I can count with intlogAttempts but I cannot write the value to the tbl to use to count every failed log on attempt, it always goes back to zero and even with a macro It doesn't work.
My goal is to,create a complete log on record where the db will write every log on (failed or succesfull) to a record, as well as every change of password, new users, deactivated users,....
Help is greatly appriciated.
thanks,
Tom
Code:
' Module : mod_display_menu
' Function : display the switchboard after checking the access and password and password expiry date
Option Compare Database
Option Explicit
Sub display_menu()
On Error GoTo err_display_menu
'*************************************************************
'* Check userId and access level *
'*************************************************************
Dim access_level As Integer
Dim finish_Date As Date
Dim port_syd As String
Dim valid_user As Integer
Dim check_user As Integer
Dim password_period As Date
Dim check_password As String
Dim strmsg As String
Dim bln_lock As Boolean
Static intLogonAttempts As Integer
valid_user = 2
' ***********************************************
' * Validate user_id *
' ***********************************************
check_user = DCount("[user_id]", "tbl_users", "user_id=forms!frm_main!user_id")
bln_lock = DLookup("[Control_lock]", "tbl_users", "user_id=forms!frm_main!user_id")
If check_user = 1 And bln_lock = False Then
valid_user = 2
Else
valid_user = 0
End If
' ********************************************************************************
' * Validate password *
' * REMARK: Changed UCase scenario to allow upper and lower case symbols *
' ********************************************************************************
If valid_user = 2 Then
check_password = DLookup("[passwords]", "tbl_users", "user_id=forms!frm_main!user_id")
If check_password = Forms!frm_main!password Then
valid_user = 2
Else
valid_user = 1
End If
End If
' **********************************************
' * Validate access_level *
' **********************************************
If valid_user = 2 Then
access_level = DLookup("[access_level]", "tbl_users", "user_id=forms!frm_main!user_id")
End If
Select Case valid_user
Case 0, 1
strmsg = " Access Denied" & _
vbCrLf & " Contact your Administrator if the problem persists. "
MsgBox strmsg, vbCritical, "INVALID USER ID or PASSWORD"
intLogonAttempts = DLookup("[Attempts]", "tbl_users", "user_id=forms!frm_main!user_id")
intLogonAttempts = intLogonAttempts + 1
'write intlogonAttempt to [Attempts] in tbl_users
If intLogonAttempts > 3 Then
MsgBox "You are locked out this database. Please contact your System Administrator.", vbCritical, "Restricted Access!"
bln_lock = True
'Application.Quit
End If
' DoCmd.Quit
Case 2
Select Case access_level
Case 1 ' Level1 menu; System Administrator
' validate password expiry
password_period = DLookup("[password_date]", "tbl_users", "user_id = forms!frm_main!user_id")
If password_period < date - 30 Then
strmsg = " Your password has expired. You must change your password"
MsgBox strmsg, vbInformation, "Expired Password"
DoCmd.OpenForm "frm_change_password", acNormal
Else
DoCmd.OpenForm "switchboard"
End If
Case 2 ' Level2 menu; super visor acount
' validate password expiry
password_period = DLookup("[password_date]", "tbl_users", "user_id = forms!frm_main!user_id")
If password_period < date - 90 Then
strmsg = " Your password has expired. You must change your password"
MsgBox strmsg, vbInformation, "Expired Password"
DoCmd.OpenForm "frm_change_password", acNormal
Else
DoCmd.OpenForm "switchboard"
End If
Case 3 ' Level3 menu; user acount
' validate password expiry
password_period = DLookup("[password_date]", "tbl_users", "user_id = forms!frm_main!user_id")
If password_period < date - 90 Then
strmsg = " Your password has expired. You must change your password"
MsgBox strmsg, vbInformation, "Expired Password"
DoCmd.OpenForm "frm_change_password", acNormal
Else
DoCmd.OpenForm "switchboard"
End If
Case Else
strmsg = " Access Denied" & _
vbCrLf & " Contact your Administrator if the problem persists. "
MsgBox strmsg, vbInformation, "INVALID USER ID or PASSWORD"
End Select
End Select
exit_display_menu:
Exit Sub
err_display_menu:
MsgBox Err.decsription
Resume exit_display_menu
End Sub
' ***********************************************************
' Form: frm_main
'
' Function : login screen
'
' Date last Modified : 26/02/2007
' 26/02/2007 - redesign for Sydney use. Sydney's menu now in a
' switchboard format
'
' ***********************************************************
Option Compare Database
Option Explicit
Private intLogonAttempts As Integer
' ******************************************************
' close form
' ******************************************************
Private Sub close_form_Click()
On Error GoTo Err_close_form_Click
DoCmd.RunMacro "macro_exit"
Exit_close_form_Click:
Exit Sub
Err_close_form_Click:
MsgBox Err.Description
Resume Exit_close_form_Click
End Sub
' ***********************************************************
' User has entered user_id and Password
' ***********************************************************
Private Sub cmdOK_Click()
On Error GoTo Err_cmdOK_Click
' Validate User ID and Password and then display menu items
display_menu
Exit_cmdOK_Click:
Exit Sub
Err_cmdOK_Click:
MsgBox Err.Description
Resume Exit_cmdOK_Click
End Sub
' ******************************************************
' maximize the screen
' ******************************************************
Private Sub Form_Load()
On Error GoTo Err_Form_Load
DoCmd.Maximize
Exit_Form_Load:
Exit Sub
Err_Form_Load:
MsgBox Err.Description
Resume Exit_Form_Load
End Sub
Private Sub Form_Open(Cancel As Integer)
'Reset Logon attempts on open form
intLogonAttempts = 0
End Sub
' ********************************************************************************
' when the user id gets the focus, the user id and password are reset to blank *
' ********************************************************************************
Private Sub user_id_GotFocus()
On Error GoTo Err_user_id_GotFocus
'remove current user and password
Me!user_id = Null
Me!password = Null
Exit_user_id_GotFocus:
Exit Sub
Err_user_id_GotFocus:
MsgBox Err.Description
Resume Exit_user_id_GotFocus
End Sub
Comment