Good eve/day guys! our defense is finish but our teacher suggest that if the user input invalid username or password 3 times it will block the user to log in.... I have a code here and it's working BUT i'm not satisfied on my code.... I FEEL it is not the proper way to code....
it is possible to use a timer to do it's job?
blockUserLogin - it means if the value is 1 the system will block the user until 10 min. past
EDIT:
any suggestion code? please feel free to post your suggestion code here.
it is possible to use a timer to do it's job?
Code:
Public Class AdminForm
Public Attempt As Integer
Dim prevAttemptTime As Date
Dim curAttemptTime As Date
Dim blockUserLogin As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim minDiff As Integer = DateDiff(DateInterval.Minute, prevAttemptTime, curAttemptTime)
Dim secDiff As Integer = DateDiff(DateInterval.Second, prevAttemptTime, curAttemptTime)
curAttemptTime = TimeOfDay
If minDiff < 1 And blockUserLogin = 1 Then ' I set it to 1 min just to test if my code is working
MsgBox("You're still unable to login. Please try again later." & vbNewLine & "Elapsed Time: " & minDiff & " min(s). " & secDiff & " sec(s).")
Else
If TextBox1.Text <> "admin" Or TextBox2.Text <> "password" Then ' It's only a dummy
Attempt += 1
If Attempt = 3 Then
blockUserLogin = 1
prevAttemptTime = TimeOfDay
MsgBox("You entered 3 consecutive invalid username and password. Please try again after 10 mins.", MsgBoxStyle.OkOnly)
TextBox1.Clear()
TextBox2.Clear()
Attempt = 0
Else
MsgBox("Invalid Username or Password. Please try again.", MsgBoxStyle.OkOnly)
TextBox1.Clear()
TextBox2.Clear()
End If
Else
Form1.DailyReportToolStripMenuItem.Enabled = True
Form1.MonthlyReportToolStripMenuItem.Enabled = True
'Form1.ShowLoggedInReportToolStripMenuItem.Enabled = True
'Form1.LoggedInReportToolStripMenuItem.Enabled = True
Form1.YouMustLogInToolStripMenuItem.Visible = False
Form1.ConsolidatedReportToolStripMenuItem.Enabled = True
TextBox1.Clear()
TextBox2.Clear()
Form1.LogInToolStripMenuItem.Enabled = False
Form1.LogoutToolStripMenuItem.Enabled = True
MsgBox("College Library User Attendance System!", MsgBoxStyle.OkOnly, "Welcome")
Me.Close()
End If
End If
End Sub
End Class
EDIT:
any suggestion code? please feel free to post your suggestion code here.