I already made security login that if failed 3 times the program will be terminated. However, I want to make a security login that will lock the system and the admin will be required to login instead.
Here's my code:
Dim nCnt As Integer
Dim nCnt2 As String
Private Sub cmdOk_Click()
nUsername = "username ='" & txtUsername.Text & "'"
npassword = txtPassword.Text
If nCnt < 2 Then
With adoLog.Recordset
.MoveFirst
.Find nUsername
If .EOF Then
MsgBox "Access Denied" & vbCrLf & "Please try again." & vbCrLf & vbCrLf & "Warning: You only have " & nCnt2 & " attempt.", vbCritical, "Terror"""
nCnt = nCnt + 1
nCnt2 = nCnt2 - 1
Label7.Caption = nCnt2
txtUsername.Text = ""
txtPassword.Text = ""
txtUsername.SetFocus
Else
If adoLog.Recordset.Fields("password").Value = npassword And adoLog.Recordset.Fields("flag").Value = 1 Then
Call Change_Flag
MsgBox "Access Granted"
cUser = adoLog.Recordset.Fields("name").Value
cPosition = adoLog.Recordset.Fields("position").Value
With adoHistory_Login.Recordset
.AddNew
.Fields("name").Value = cUser
.Fields("position").Value = cPosition
.Fields("time_login").Value = Time()
.Fields("date_login").Value = Date
.Fields("date_logout").Value = Date
.Update
开发者_如何学Go Me.Refresh
frmMain.Show
frmMain.SetFocus
End With
Unload Me
txtUsername.Text = ""
txtPassword.Text = ""
Else
MsgBox "Access Denied" & vbCrLf & "Please try again." & vbCrLf & vbCrLf & "Warning: You only have " & nCnt2 & " attempt.", vbCritical, "Terror"""
nCnt = nCnt + 1
nCnt2 = nCnt2 - 1
Label7.Caption = nCnt2
txtUsername.Text = ""
txtPassword.Text = ""
txtUsername.SetFocus
End If
End If
End With
Else
Call block
End
End If
End Sub
Private Sub Change_Flag()
With adoLog.Recordset
.Fields("flag").Value = 0
End With
End Sub
Private Sub block()
MsgBox "You already used all attempt." & vbCrLf & "This will terminate the application.", vbCritical, "Terror"
End Sub
Private Sub Form_Initialize()
cmdOK.Enabled = False
txtPassword.Enabled = False
cmdRegister.Visible = False
If adoLog.Recordset.RecordCount <> 0 Then
cmdOK.Enabled = False
txtPassword.Enabled = False
txtUsername.Enabled = True
Else
cmdRegister.Visible = True
txtUsername.Enabled = False
End If
End Sub
Private Sub Form_Load()
nCnt2 = 2
Label7.Caption = nCnt2
End Sub
You will need to store an additional flag somewhere to indicate that login is denied and then check this flag before attempting the login. You will also need to store the account type and check to see if the account is allowed to log in even if this flag is set.
Are you wanting to lock out the full PC or the username that is being used?
Add a new column to the recordset for IsLocked
and have it get set to true after the 3 logins (Make sure you provide some way for the admin to clear it back out though).
As soon as the username is used check IsLocked
first before the password and kick it out immediately with the appropriate message.
Also, make sure you prevent the IsLocked
from ever being set on the admin username.
精彩评论