我的登錄系統出現問題,在使用第一個用戶(管理員)時尋求一些極客幫助系統做它需要做的事情。但是,當我嘗試用不同的用戶登錄時,它將無法工作。我讓我的錯誤username and password unknown
,當我刪除代碼,我可以與其他所有用戶的登錄以下行,VB中的登錄系統問題
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
感謝在這個問題上的任何幫助。
您使用的是ASP.NET提供的數據庫還是您自己的數據庫? – Zeddy 2013-04-22 22:43:18
什麼是記錄*到*? – 2013-04-22 23:10:47
你爲什麼要遍歷用戶表中的行?你應該根據用戶名選擇1行,而不是整個表。 – Tim 2013-04-23 04:58:30