-------------------------Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
002
003
If ComboBox1.Text =
""
Or TextBox1.Text =
Or TextBox2.Text =
Then
004
MessageBox.Show(
"Invalid Username and Password!"
,
"Invalid"
, MessageBoxButtons.OK, MessageBoxIcon.Warning)
005
TextBox1.Text =
006
TextBox2.Text =
007
ComboBox1.Text =
"Select"
008
009
'
for
administrator
010
011
ElseIf ComboBox1.Text =
"Administrator"
012
Static iPassCount As Integer ' this will assure that the counter is visible only locally but not lost from call to call
013
If TextBox1.Text =
"admin"
And TextBox2.Text =
"nimda"
014
Dim log As New LoginForm
015
log.Show()
016
iPassCount = 0 ' If passwor is ok
then
reset the counter
017
Me.Hide()
018
019
Else
020
iPassCount += 1 ' increase the counter
021
022
If iPassCount < 4 Then '
while
less
than 3 retries notify the user
023
024
"Invalid Username and Password for "
& vbNewLine & (
" Administrator"
),
025
026
Else ' almost 3
times
failed to enter the password
027
If MessageBox.Show(
"Do you want to retrieve your password?"
"Forgot Password"
, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes Then
028
Dim fp As New ForgotPassword
029
fp.Show()
030
031
032
End If
033
034
035
036
037
038
librarian
039
040
"Librarian"
041
042
Static iPassCount1 As Integer
043
"librarian"
044
045
iPassCount1 = 0 ' If password is ok
046
047
048
049
iPassCount1 += 1 ' increase the counter
050
If iPassCount1 < 4 Then '
051
" Librarian"
052
053
054
055
056
057
058
059
060
061
user
062
063
"User"
064
065
Static iPassCount2 As Integer
066
Dim connection As New OleDbConnection
067
Dim userpassquery As New OleDbCommand
068
Dim datareader As OleDbDataReader
069
070
071
072
MsgBox(
"Please enter a Username and Password!"
)
073
074
075
connection.ConnectionString = connectionString
076
userpassquery.CommandText =
"SELECT Username, LastName FROM Registration WHERE Username= '"
& TextBox1.Text &
"';"
077
connection.Open()
078
079
userpassquery.Connection = connection
080
081
datareader = userpassquery.ExecuteReader
082
datareader.Read()
083
084
085
'Done querying
086
'Check
if
username is
in
the database
087
088
089
'Username exists
090
If datareader.HasRows = True Then
091
password is correct
092
093
094
'Determine level of access
095
096
Dim a As New user
097
a.Show()
098
099
iPassCount2 = 0 ' If password is ok
100
101
102
103
iPassCount2 += 1 ' increase the counter
104
If iPassCount2 < 4 Then '
105
106
107
108
Dim SecretQuestion As New OleDbCommand
109
Dim connection1 As New OleDbConnection
110
Dim datareader1 As OleDbDataReader
111
112
113
' almost 3
114
Dim strName As String
115
116
117
strName = InputBox(
"Please enter your Username"
"Retrieve"
118
119
Dim secret As New ForgotPassword
120
Dim SecretAnswer As String
121
secret.Show()
122
123
124
connection1.ConnectionString = connectionString
125
SecretQuestion.CommandText =
"SELECT SecretQuestion FROM Registration WHERE Username= '"
& strName &
126
SecretAnswer =
"SELECT SecretAnswer FROM Registration WHERE Username= '"
127
connection1.Open()
128
[i]
129
130
'forgot password label and textbox. please see the forgot password :)
131
132
ForgotPassword.Label3.Text = SecretQuestion.CommandText
133
ForgotPassword.TextBox2.Text = SecretAnswer
134
135
SecretQuestion.Connection = connection1
136
datareader1 = SecretQuestion.ExecuteReader
137
datareader1.Read()
138
139
connection1.Close()
140
connection1.Dispose()
141
142
143
[/i]
144
145
146
147
148
149
150
connection.Close()
151
connection.Dispose()
152
153
154
155
156
157
158
159
End Sub