我的登录系统有问题,并在使用第一个用户(管理员)时寻求一些极客帮助,系统会做它需要做的事情。但是当我尝试使用其他用户登录时,它将无法正常工作。我得到了我的错误username and password unknown
,当我从代码中删除以下行时,我可以与所有其他用户一起登录,
ElseIf (currentUser <> username AndAlso currentPassword <> password) Then
MessageBox.Show("Username and password unknown", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
源代码,
Public Function Login(ByVal username As String, ByVal password As String)
Dim usersDatasSet As New DataSet()
usersDataAdapter.FillSchema(usersDatasSet, SchemaType.Source, "Users")
usersDataAdapter.Fill(usersDatasSet, "Users")
Dim table As DataTable = usersDatasSet.Tables("Users")
For i As Integer = 0 To table.Rows.Count - 1
Dim currentUser As String = table.Rows(i)("Username").ToString().Trim()
Dim currentPassword As String = table.Rows(i)("Password").ToString().Trim()
'Check input
If (currentUser <> username And currentPassword = password) Then
MessageBox.Show("Unknown user", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
ElseIf (currentUser = username And currentPassword <> password) Then
MessageBox.Show("Wrong password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
ElseIf (currentUser <> username AndAlso currentPassword <> password) Then
MessageBox.Show("Username and password unknown", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
ElseIf (currentUser = username AndAlso currentPassword = password) Then
usersDatasSet.Dispose()
Connection.Close()
Return True
End If
Next
usersDatasSet.Dispose()
Connection.Close()
Return False
End Function
感谢您在此问题上的任何帮助。