hey
im real sorry about this but none of the forums ive looked at help me much.
basicly ive created a database for usernames and passwords and i want to make vb check the database for passwords and usernames. im usine vb6.0 if any one could just tell me the script...

Recommended Answers

All 4 Replies

so show you effort this far...:)

hey
im real sorry about this but none of the forums ive looked at help me much.
basicly ive created a database for usernames and passwords and i want to make vb check the database for passwords and usernames. im usine vb6.0 if any one could just tell me the script...

as Jx_Man said you must provide us what have you done so far. ok as this is your first time visit i'm providing you the script. here is a sample snippet for you. try it.

this script is based on access database. if you are using any other rdbms then you have to change the provider name in the connection string accordingly.

don't just copy and paste this from here to your form. replace the following with your objects :-
1. user.mdb --> database name. change with your db name
2. info --> table name. change with your table name
[this table contains two columns; username and password. so change accordingly what you have in your table]
3. txtusername --> textbox accepting username from user. change with your textbox object name
4. txtpassword --> textbox accepting password. change with your password textbox object name

and add a reference to Microsoft Activex Data Objects <version no.> Library from Project->References

Option Explicit

Dim gcn As New ADODB.Connection

Private Sub Command1_Click()
Dim str As String
Dim rs As New ADODB.Recordset

If Trim(txtusername.Text) = "" Then
    MsgBox "Mention username."
    txtusername.SetFocus
    Exit Sub
End If

If Trim(txtpassword.Text) = "" Then
    MsgBox "Mention password."
    txtpassword.SetFocus
    Exit Sub
End If

str = "select * from info where username='" & Trim(txtusername.Text) & _
        "' and password='" & Trim(txtpassword.Text) & "'"
rs.Open str, gcn, 1, 2

If rs.RecordCount > 0 Then
    Unload Me
    MsgBox "Welcome to system."
    End
Else
    MsgBox "Invalid username or password." & vbCrLf & "Please re-try..."
    txtusername.Text = ""
    txtpassword.Text = ""
    txtusername.SetFocus
End If

If rs.State = adStateOpen Then rs.Close
Set rs = Nothing
End Sub

Private Sub Form_Load()
gcn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & _
            "\user.mdb;Persist Security Info=False"
gcn.Open
End Sub

don't forget to give us your feedback.

regards
Shouvik

great simple code from shouvik... try it friend and give a feedback :)

The code from Shouvik will work fine. But i would recommend you to use use COUNT to findout existance of the username and password in the database.

1.Accept the username and password from user input.
2.In the database username field should be the primary/unique key to avaoid duplicate user name.
3.Check for existance of the same useing COUNT().
4.Login to application iof count returns 1 else ask to re-enter the username and password.

Since using COUNT this will give you better performance even in case of a large user database.

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.