Option Compare Database
Option Explicit
'Module name : clsLogin
'Description : This class module deals with the authenication of a user by checking their
' : login details on the user table.
'Developed By : Rob Boyle
'Example : See form (frmLogin) example for full instructions and example code
Public strIusername As String
Public strIpassword As String
Public strTable As String
Public strUsernameField As String
Public strPasswordField As String
Public Property Let Username(strParam As String)
'Accepts a username for searching
strIusername = strParam
End Property
Public Property Get Username() As String
'Return username
Username = strIusername
End Property
Public Property Let Password(strParam As String)
'Accepts a username for searching
strIpassword = strParam
End Property
Public Property Get Password() As String
'Return password
Password = strIpassword
End Property
Public Property Get ValidUser() As Boolean
'Returns boolean value depending on whether user is on system or not
If ConfirmUser Then
'User is on system
ValidUser = True
Else
ValidUser = False
End If
End Property
Public Property Let Table(strParam As String)
'Set table var
strTable = strParam
End Property
Public Property Let UsernameField(strParam As String)
'Gets the username field from the table
If IsNull(strParam) Then
MsgBox "Please supply the username field from the table! ", vbExclamation, "No username field supplied"
Exit Property
End If
'Set username var
strUsernameField = strParam
End Property
Public Property Let PasswordField(strParam As String)
'Set username var
strPasswordField = strParam
End Property
Private Function ConfirmUser() As Boolean
'Confirms user details by checking user table
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
With rs
.ActiveConnection = CurrentProject.Connection
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Source = "SELECT * FROM " & strTable & " WHERE " & strUsernameField & " = '" & strIusername & "' AND " & _
strPasswordField & " = '" & strIpassword & "'"
.Open
'Check if details are valid
If .RecordCount = 0 Then
'User is not on the system
ConfirmUser = False
GoTo CloseRS
End If
'Set any additional global variables here eg.
'strAccesslevel = .Fields("AccessLevel")
'User is on the system
ConfirmUser = True
CloseRS:
'Close the connection
.Close
End With
'Reset the recordset variable
Set rs = Nothing
End Function