Module Main
Friend blnLoggedIn As Boolean
Dim arrUsernames() As String = {"Admin, Clerk, Manager"}
Dim arrPasswords() As String = {"P@ssword, pa$$word, and passw0rd"}
Sub Login(username As String, password As String)
blnLoggedIn = False
If VerifyUsername(username) And VerifyPassword(password) Then
'Find index for username
Dim userIndex As Integer
For loopIndex = 0 To arrUsernames.Length - 1
If arrUsernames(loopIndex) = username Then
userIndex = loopIndex
Exit For
End If
Next
'Check for password match
If arrPasswords(userIndex) = password Then
blnLoggedIn = True
Else
MessageBox.Show(“Incorrect password.”)
End If
End If
End Sub
Function VerifyUsername(username As String) As Boolean
'If the username is found, Return True, otherwise Return False
End Function
Function VerifyPassword(password As String) As Boolean
'If the passwords match, Return True, otherwise Return False
End Function
End Module
我的指示说:
使用您对搜索数组的了解,实现VerifyUsername和VerifyPassword函数。如果在arrUsernames或arrPasswords数组中分别找到用户名或密码,则它们应该返回true。