954,559 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

code for login and password..using vb6

Hi,

Front end Vb6, back end.. access... connection.. ODADB... can someone please help me with the code for login and password.

stackOverflow
Junior Poster
116 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

so, the usernames and passwords are stored in an access database?

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 
so, the usernames and passwords are stored in an access database?


yes...they are stored in access

stackOverflow
Junior Poster
116 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

Ummm I'm probobly no help...but part of the thing could be done...

IF strUserName="____" AND strPassoword="________" THEN
What happens when you do that
ELSE
It dosn't
END IF

Kiba Ookami
Junior Poster in Training
66 posts since Jan 2005
Reputation Points: 10
Solved Threads: 1
 

how does the access table look, and what are the field names?

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

Hi,

Front end Vb6, back end.. access... connection.. ODADB... can someone please help me with the code for login and password.

Hi,

just to give some inputs:

in your form you need to have 2 txt field:
1. txtlogin
2: txtpwd

then:

Private Sub txtpwd_KeyPress(KeyAscii As Integer)
If KeyAscii = vbEnter Then
    If Len(Trim(txtlogin)) > 0 And Len(Trim(txtpwd)) > 0 Then
        If CheckPwd(txtlogin, txtpwd) = "ok" Then
            MsgBox "Password ok"
        Else
            MsgBox "Wrong password or Login not found."
        End If
    Else
        MsgBox "Login and password should not be blank"
    End If
End If
End Sub

Private Function CheckPwd(cLogin As String, cPwd As String)
'in my case i will use dao. you probably using ado just convert it
Dim rs As Recordset, ret As String
Set rs = opendatabase("c:\temp\login.mdb").openrecordset("select * from tbllogin where ucase(trim(logname)) = '" & UCase(Trim(cLogin)) & "'")
If rs.RecordCount <> 0 Then
    If UCase(Trim(rs("pword"))) = UCase(Trim(cPwd)) Then
        ret = "ok"
    Else
        ret = "wrong"
    End If
Else
    ret = "wrong"
End If
rs.Close: CheckPwd = ret
End Function

'This is just to give you an idea. For sure there are lot of ways of doing it...


Newvbguy

NewVBguy
Junior Poster in Training
71 posts since Mar 2005
Reputation Points: 13
Solved Threads: 3
 

Just wanted to thank you for the code - This was incredibly helpful.

I set up a similar situation and thought I'd share my code.

Differences:I have not included a keyPress Sub but did it from a button click instead.
I call from the current database instead of a different one.
The recordset is exited as soon as possible, and then any conditions not concerning the recordset are administered.
I could have used a function, but this was a quickie. Most likely will update this to include keypress as well as button click in which both subs call a function.

The table accessed (AdminUser) contains a primary key called 'UserID' [text] and a 'Password' field.

My txtBoxes are named txtUser, and txtPassword

Lots of comments - hope it helps anyone.

Private Sub cmdMaintenanceSwitchboard_Click()
    
    'check for null password
    If IsNull(Trim(txtUser)) Then
        MsgBox "User Name required.", vbExclamation
        txtUser.SetFocus
        Exit Sub
    End If
    
    'check for null password
    If IsNull(Trim(txtPassword)) Then
        MsgBox "Password required.", vbExclamation
        txtPassword.SetFocus
        Exit Sub
    End If
    
    'To use the following code, open the code window for a form.
    'Under the Tools/References menu, enable the "Microsoft DAO 3.6 Object Library"
    'and some may have to disable the "Microsoft ActiveX Data Objects Library"
    
    'declare variables (tempRecordSet becomes an object variable)
    Dim tempRecordSet As Recordset, Password As String
    
    'open the AdminUsers table
    '(recordset object variables allow access to records and fields in tables and queries.
    'This modified version opens a recordset via a SQL statement to pull the record (if any) where the field matches the txtUser field in the form.
    'Since the field is a primary key, there should only be one record if any matches are found.
    Set tempRecordSet = CurrentDb.OpenRecordset("select * from AdminUsers where UCase(trim(UserID)) = '" & UCase(Trim(txtUser)) & "'")
    
    'retrieve the Password field from the AdminUsers table if the UserID matches the txtUser Field
    If tempRecordSet.RecordCount <> 0 Then
        Password = UCase(Trim(tempRecordSet("Password")))
    End If
    
    'close the recordset and release the recordset object variable
    tempRecordSet.Close
    Set tempRecordSet = Nothing
    
    'check the password
    If Password <> UCase(Trim(txtPassword)) Then
       MsgBox "Incorrect password", vbExclamation
    Else
        'passwords match, allow the user to the maintenance switchboard
        MsgBox "Congratulations! Right Password!!!", vbExclamation
    End If
    txtPassword = Empty
End Sub
naiJenn
Newbie Poster
1 post since Nov 2006
Reputation Points: 10
Solved Threads: 0
 

please don't resurrect two year old threads. Thread closed.

Ancient Dragon
Retired & Loving It
Team Colleague
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You