PerkinsSlave
New Member
- Joined
- Feb 1, 2004
- Messages
- 26
Morning,
I have created a security log-in for a database. I would like to lock users out after four unsuccessful log-in attempts.
I have the following tables and forms:
- tblUserIDs contains UserID, Password, SecurityLevel, and AccountLocked
The default for account locked, which is a Yes/No, is unchecked. Once it's checked, the account should be locked out. Here's the code once the user enters their ID and password and presses the Enter button:
Private Sub cmdEnter_Click()
Dim AccType As String
Dim lcnt As Long
Dim lockout As Integer
lockout = 0
lcnt = DCount("[AutoNumber]", "tblUserIDs", "[UserID] = '" & Me.txtUserID & "' and [Password] = '" & Me.txtPassword & "'")
If lcnt <> 1 Then
lockout = lockout + 1
If lockout >= 5 Then
MsgBox "Your account has been locked out. Please contact the system administrator.", vbCritical, "Login Error"
Me.txtUserID = Null
Me.txtPassword = Null
Me.txtUserID.SetFocus
Exit Sub
Else
MsgBox "Invalid user ID or password, please try again.", vbExclamation, "Login Error"
Me.txtUserID = Null
Me.txtPassword = Null
Me.txtUserID.SetFocus
Me.chkChangePassword.Value = 0
Exit Sub
End If
Else
AccType = Nz(DLookup("SecurityLevel", "tblUserIDs", "[UserID] = '" & Me.txtUserID & "'"), "")
If AccType <> "" Then ' if the security level has been set, then:
If Me.chkChangePassword.Value = -1 Then
gblUserID = Me.txtUserID ' attach the user id to the global string
gblAccType = AccType ' attach the account type to the global string
Call LogSignIns(Now()) ' log this sign-in
DoCmd.Close
DoCmd.OpenForm "sl-frmChangePassword"
Else
gblUserID = Me.txtUserID ' attach the user id to the global string
gblAccType = AccType ' attach the account type to the global string
Call LogSignIns(Now()) ' log this sign-in
DoCmd.Close
DoCmd.OpenForm "frmMain Menu"
End If
Else ' if the security level has NOT been set, then:
MsgBox "Your account has been locked out. Please contact the system administrator.", vbCritical, "Login Error"
Me.txtUserID.SetFocus
Exit Sub
End If
End If
End Sub
My first thought was to set a counter. As you can see, the counter resets everytime you enter the sub. That part is fine. What I would like to do is, once the counter is > 4, set the checkbox.
I can make that happen, but it won't save to the table. What I can't figure out is how to change the text box in the underlying table without changing the rest of the record, and without creating a new record.
I was thinking some kind of SQL statement, or else maybe using DAO commands such as .Edit, but I can't figure out how to make it work. Any ideas? Or does anyone have a security sub they'd like to share? This one does work perfectly, except for the password lockout.
Thanks!!
I have created a security log-in for a database. I would like to lock users out after four unsuccessful log-in attempts.
I have the following tables and forms:
- tblUserIDs contains UserID, Password, SecurityLevel, and AccountLocked
The default for account locked, which is a Yes/No, is unchecked. Once it's checked, the account should be locked out. Here's the code once the user enters their ID and password and presses the Enter button:
Private Sub cmdEnter_Click()
Dim AccType As String
Dim lcnt As Long
Dim lockout As Integer
lockout = 0
lcnt = DCount("[AutoNumber]", "tblUserIDs", "[UserID] = '" & Me.txtUserID & "' and [Password] = '" & Me.txtPassword & "'")
If lcnt <> 1 Then
lockout = lockout + 1
If lockout >= 5 Then
MsgBox "Your account has been locked out. Please contact the system administrator.", vbCritical, "Login Error"
Me.txtUserID = Null
Me.txtPassword = Null
Me.txtUserID.SetFocus
Exit Sub
Else
MsgBox "Invalid user ID or password, please try again.", vbExclamation, "Login Error"
Me.txtUserID = Null
Me.txtPassword = Null
Me.txtUserID.SetFocus
Me.chkChangePassword.Value = 0
Exit Sub
End If
Else
AccType = Nz(DLookup("SecurityLevel", "tblUserIDs", "[UserID] = '" & Me.txtUserID & "'"), "")
If AccType <> "" Then ' if the security level has been set, then:
If Me.chkChangePassword.Value = -1 Then
gblUserID = Me.txtUserID ' attach the user id to the global string
gblAccType = AccType ' attach the account type to the global string
Call LogSignIns(Now()) ' log this sign-in
DoCmd.Close
DoCmd.OpenForm "sl-frmChangePassword"
Else
gblUserID = Me.txtUserID ' attach the user id to the global string
gblAccType = AccType ' attach the account type to the global string
Call LogSignIns(Now()) ' log this sign-in
DoCmd.Close
DoCmd.OpenForm "frmMain Menu"
End If
Else ' if the security level has NOT been set, then:
MsgBox "Your account has been locked out. Please contact the system administrator.", vbCritical, "Login Error"
Me.txtUserID.SetFocus
Exit Sub
End If
End If
End Sub
My first thought was to set a counter. As you can see, the counter resets everytime you enter the sub. That part is fine. What I would like to do is, once the counter is > 4, set the checkbox.
I can make that happen, but it won't save to the table. What I can't figure out is how to change the text box in the underlying table without changing the rest of the record, and without creating a new record.
I was thinking some kind of SQL statement, or else maybe using DAO commands such as .Edit, but I can't figure out how to make it work. Any ideas? Or does anyone have a security sub they'd like to share? This one does work perfectly, except for the password lockout.
Thanks!!