hi, all
im working in access 2007 vba, i write a code in the login screen, to check if the user name and password match with the corresponding username and password in the database.
the problem im facing is if a user enters a usernam correct and a password which matches another user name the system will login.
example:
username:saad,,, password:saad, accounttype: admin.
username:jhone,, password:jhon, accounttpe: manager.
if jhone entered his username and the password of saad the system will log him as admin.
Public Sub Command4_Click()
If IsNull([Combo0]) = True Then 'Check UserName
MsgBox "Username is required", vbOKOnly, "Required Data"
ElseIf IsNull([PASSWORD]) = True Then 'Check Password
MsgBox "Password is required", vbOKOnly, "Required Data"
Else
If Me.PASSWORD.Value = DLookup("USERNAME", "SYS_USER", "[password]='" & Me.PASSWORD.Value & "'") Then
strUser = Me.Combo0.Value 'Set the value of strUser declared as Global Variable
strAccountType = DLookup("USER_TYPE", "SYS_USER", "[password]='" & Me.PASSWORD.Value & "'") 'set the value of strRole declared as Global Variable
DoCmd.Close
MsgBox "Welcome Back, " & strAccountType, vbOKOnly, "Welcome"
DoCmd.OpenForm "First Screen"
Else
MsgBox "Invalid Password. Please try again.", vbOKOnly, "Invalid Password"
PASSWORD.SetFocus
End If
End If
End Sub