
Validating password/login via ADO
Michael:
Since you are working with ADO I suggest to create a class object which
deals with the DB session. Something like this:
create a class module and name it dbSession.cls (or whatever you want to
name it)
Public Function CheckLogin(ByVal userID As String, ByVal password As String)
As Boolean
Dim conn As ADODB.Connection
Set conn = GetConn() '*call connection using GetConn method
of the object
If conn Is Nothing Then Exit Function
Dim sSQL As String
sSQL = "SELECT * FROM Tusers WHERE Tusers.userId = '" & userId &
"'" '* Select one specific user record maching userId
Dim rs As New ADODB.Recordset
rs.Open sSQL, conn, adOpenStatic, adLockReadOnly '*the SQL is
passed to the Open method, Open executes and either returns 1 or 0
If rs.RecordCount <= 0 Then Exit Function '*if you don't exit
at this point you have a valid connection and a valid username
If password <> rs!password Then Exit Function '*compare the
password of the current user to the value stored in the recordset
CheckLogin = True '* if
you match you are in
End Function
I should point out that I found this code in a book called "Visual Basic 6.0
from Scratch" and I have adapted it to my needs. It does the job
beautifully.
Quote:
> Can I use multiple parameters in the select statement to match username
and
> password values in the database. I can only get it to match on one field
> then try to use the field in the recordset to match the other.
> > I kow this is probably an oversight somewhere on my part but I am having
a
> > problem trying to validate both the password and username through the
ADO.
> > Can someone help me out.
> > Thanks