Hi,

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

lester0233 commented: Private Sub Command1_Click() End End Sub Private Sub Command2_Click() LogOn End Sub Private Sub Form_Load() Dbase End Sub Public Sub LogOn() On Error Resume Next Dim ctr As Integer Set rs = New ADODB.Recordset rs.Open "Select * From [tbl_user]", +0

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

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

yes...they are stored in access

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

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

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

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

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

private sub command1_()
adodc1.recordset.addnew
end sub

Private Sub CMDLOGIN_Click()
cn.Open GetConnString

rs.Open "Select * from SYSTEMUSERS where UserName='" & txtusername.Text & "' AND Passwords='" & Txtpasword.Text & "'", cn, adOpenKeyset, adLockOptimistic

If rs.RecordCount >= 1 And rs!isactive = True Then
LoginSuccess = True
MsgBox "CONGRATULATION!RIGHT PASSWORD!!!", vbExclamation

        Select Case rs!usergroup

        Case 1

        Case 2
            MDIForm1.MNUEDITFORM.Visible = False
        Case 3
            MDIForm1.MNUEDITFORM.Visible = False
        Case Else

        End Select

Unload Me

Else

     MsgBox "Try Again"

End If

End Sub

bruce
i hve maked a login form but when i click on a cmd buttom nothing is displayed.

private sub Cmdlogin_Click

if Txt1.text="admin" and Txt2.text="admin" then
MDIForm.show
else
Txt1.text=""
Txt2.text=""

end if

end sub

what is the code for log in that when you put the password it is already in an asterisk form ..
thnak you

commented: Im having trouble replying on this thing. Could you please look at the post under this +0

for that you can click on the text box in which the user will enter the password, and in the little properties table on the side there is a box that says "passwordcharacter". You will see that the box next to it is empty so put an asterick in it. Then you will see that any text in the text box will be written in astericks including the caption of the textbox. There will be one astericks for each letter.

HI i just want an login page code for my library mangement project front end is vb6.0 and back end is access( i dont know wat is front end and back end just iam using both)

how to vb6 project forget username and password..???

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.