hi

can anyone help me how to compare user and password from a database like access... for example i have registered a user and password in access then when i input the user to VB and the password it will compare if the user exist and if the password is right for that existing user.... just like a log in system...:cheesy:

Member Avatar for Dukane

Well, I can't go into specifics because I don't know too much about database programming, but I can take a stab at what you'll need to do in order to make it work.

1. Search the database for the entered user name's record. If no match, display a "wrong username" error message. If there is a match:
2. Read that whole user name/password record from the database.
3. Compare the password field to the entered password. If no match, display a "wrong password" error message. If there is a match:
4. Method is complete.

what i mean is what can i use? for example

if cbouser.txt = "the user in the database" then
blah

what can i use for the user choosed in the combo box to be compared in the databassed i made so that it will check if its valid or not...what im trying to make is that it has multiple user that can access to it and differend password each..thanks

try this:

databaseName.Open "Select * from TableUserPass where FieldUser like '" & comboUser.text & "'and FieldPass like '" & textPass.text & "',connection,3,3

//Put this in your command button//

Did you get your simple password system working? I have a similar task: I want certain passwords to open form A and certain passwords to open form B.\

Can you help?

Did you get your simple password system working? I have a similar task: I want certain passwords to open form A and certain passwords to open form B.\

Can you help?

Start a new thread (since this one is darkmessenger's) and explain in detail what you need.

try this:

databaseName.Open "Select * from TableUserPass where FieldUser like '" & comboUser.text & "'and FieldPass like '" & textPass.text & "',connection,3,3

//Put this in your command button//

Hi, may i ask what's the connection for and the 3,3 for? i'm having the same problem. im trying to use what u suggested.

thanks!

' Well this is a litle example of how to block an user in a system it depend on the way you want 'to do it, because if you want to block an id who put 3 times a wrong password you have to be 'sure if it is the same id he is trying that`s the reason why y block the user
' textbox after he put the rigth id, why i do it to this way? just to show that you can do everything 'you want but you have to know What do you want to do! so you can mix thing to get a better 'login, 'but that's your job! i hope this help you!

' first you need to textbox named TxtUser and TxtPassword
' and a command buttom named CmdOK  
' o whatever you want to named! 
'and crate the Database  on Access, whit the fields user, password, name and  state
' and put and user to try, example:  hiddenben, 1234,  hidden, Active
' make sure is in the Field State to Write 'Active' whitout spaces
' and put the DB in the same Folder as your Program! 

' This Works with Access And Dao, (i prefer ADO is better, but the netx time  :mrgreen:)

' Here we Declare our Vars
Dim cn As DAO.Database, rs As DAO.Recordset, intent As Integer
-----------------------------------------------------------------------------
Private Sub Form_Load()
' we open the database with our Dao var on the form load
Set cn = OpenDatabase(App.Path & "\Examplelogin.Mdb")
End Sub
-----------------------------------------------------------------------------
Private Sub TxtUser_LostFocus()
' with this recordset we verify is the user is ok!  and state is active! if ' not 3 times we just finish the program and nobody is block
Set rs = cn.OpenRecordset("Select * From user Where user='" &  Me.TxtUser & "' and state = 'Active'", 2, 3)
    If rs.EOF = False Then
        Me.TxtUser.Enabled = False
        intent = 0   
'we put this in 0 because we going to use again to verify password
        rs.Close
        Me.TxtPassword.SetFocus
    Else
 'if not we increase then trys and return the focus to the user textbox
        MsgBox "Incorrect", vbInformation + vbOKOnly, "Information"
        intent = intent + 1
        rs.Close
        If intent < 3 Then
            Me.TxtUser.SetFocus
            Exit Sub
        Else
            MsgBox "Incorrect Please contact the Administrator", _ vbInformation + vbOKOnly, "Information"
            End
        End If
    End If
End Sub
--------------------------------------------------------------------------------
' with this recordset we verify is the password is ok! if not 3 times 
' we block the user
Private Sub CmdOk_Click()

Set rs = cn.OpenRecordset("Select * From user Where user='" & _ Me.TxtUser & "' and password='" & Me.TxtPassword & "'", 2, 3)

    If rs.EOF = False Then
        ' if the user is correct we pass the control to our first Form

        MsgBox "Welcome '" & Me.TxtUser & "'", vbInformation + _ vbOKOnly, "Information"

        Unload Me
        rs.Close
        MDIForm1.Show
    Else
        'if not we increase then trys and return the focus to the
        ' password textbox
        MsgBox "Incorrect", vbInformation + vbOKOnly, "Information"
        intent = intent + 1
        rs.Close
        If intent < 3 Then
            Me.TxtPassword.SetFocus
            Exit Sub
        Else
            Call block   'we call the function to block the user
            MsgBox "Incorrect Your UserId is blocked Please contact _ the Administrator", vbExclamation + vbOKOnly, "Wrong"
            End
        End If
    End If
End Sub
-------------------------------------------------------------------------------
' this is the function that block the user in the Access Database
Sub block()
' a simple RecordSet
Set rs = cn.OpenRecordset("Select * From user Where user='" & Me.TxtUser & "'", 2, 3)
    rs.Edit
    rs!State = "Blocked"    'Update the State of the user on the DB
    rs.Update
    rs.Close
End Sub
------------------------------------------------------------------------------
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.