tanker
Oct 9th, 2000, 02:30 PM
I am having some trouble making my login screen work properly. I have an Access database named eiss.mdb. The table in the database is called [Security]. And the fields in that table are called [Username] & [Password]. In my program I have a login screen that has two text boxes; Username and Password; and two Command buttons; OK and Cancel. My question to you is what code would I use to make this login screen validate the username and password every time? Also what else do I need to add; if anything; to the login screen to make this work? I am including the code that I have right now. . .it doesn't work but maybe it will be somewhere to start.
Private Sub cmdCancel_Click()
End
End Sub
Private Sub CmdOK_Click()
'On your CmdOK_Click event of the login screen.
Select Case ValidateUser(txtUserName, txtPassword)
Case 0
MsgBox "Successful Login.", vbOKOnly + vbInformation, "Logon"
Me.Hide
frmMain.Show
Case 4
MsgBox "Successful Login", vbInformation + vbOKOnly, "Logon"
Me.Hide
frmMain.Show
Case 1
MsgBox "Invalid User ID.", vbInformation + vbOKOnly
txtUserName.SetFocus
Case 2
MsgBox "Invalid User Password.", vbInformation + vbOKOnly
txtPassword.SetFocus
End Select
End Sub
Private Function ValidateUser(ByVal lpUserID As String, ByVal lpUserPwd As String) As Integer
Data1.Recordset.Index = "UserID"
Data1.Recordset.Seek "=", lpUserID
If Not Data1.Recordset.NoMatch Then
If StrComp(lpUserPwd, Data1.Recordset!UserPwd, vbBinaryCompare) = 0 Then
If Data1.Recordset("Specialuser") = True Then
ValidateUser = 0
ElseIf Data1.Recordset("SpecialUser") = False Then
ValidateUser = 4
End If
Else
ValidateUser = 2
End If
Else 'if there is no match in the userid
ValidateUser = 1
End If
End Function
Private Sub cmdCancel_Click()
End
End Sub
Private Sub CmdOK_Click()
'On your CmdOK_Click event of the login screen.
Select Case ValidateUser(txtUserName, txtPassword)
Case 0
MsgBox "Successful Login.", vbOKOnly + vbInformation, "Logon"
Me.Hide
frmMain.Show
Case 4
MsgBox "Successful Login", vbInformation + vbOKOnly, "Logon"
Me.Hide
frmMain.Show
Case 1
MsgBox "Invalid User ID.", vbInformation + vbOKOnly
txtUserName.SetFocus
Case 2
MsgBox "Invalid User Password.", vbInformation + vbOKOnly
txtPassword.SetFocus
End Select
End Sub
Private Function ValidateUser(ByVal lpUserID As String, ByVal lpUserPwd As String) As Integer
Data1.Recordset.Index = "UserID"
Data1.Recordset.Seek "=", lpUserID
If Not Data1.Recordset.NoMatch Then
If StrComp(lpUserPwd, Data1.Recordset!UserPwd, vbBinaryCompare) = 0 Then
If Data1.Recordset("Specialuser") = True Then
ValidateUser = 0
ElseIf Data1.Recordset("SpecialUser") = False Then
ValidateUser = 4
End If
Else
ValidateUser = 2
End If
Else 'if there is no match in the userid
ValidateUser = 1
End If
End Function