Problem with databases

11-11-2004, 04:21 PM
Hi, I am having trouble with a database. I got a table in the database with user name and passwords. I got a logon form with a datacombo for the user name and a text box for the password. What I need to do is once you select a user name form the datacombo I want to type the password and the program needs to find if the passowrd belongs to the user name from the database. I am using ADO for this connection. The name of the recordset is rstLogon. Once I selct the name and the password is right it should go to the next form once I press ok. If it's wrong it should give me a msgbox saying it's worng. Please help. Thanks

11-11-2004, 11:15 PM
Can you post the code you have created that you are having trouble with? That will make it easier for us to suggest a way to solve your problem or help you create the functionality you are looking for.

11-12-2004, 12:24 PM
Here is a section of code that I wrote for a login screen. Hope this helps. My table from the database that has my information is stored in a table called Passwords. The two fields used from this table in my code are User_Name and Password. I also have textboxes (txtUsername and txtPassword) for both username and password, along with a blank label area (lblMessage) below the two textboxes that will display the error message. If there is a successful login, my program loads a form called frmEmployeeBalance. Last, my button to run this code is called btnSubmit. I just wanted to point out my differences from what yours is set up like so that you can substitute your info in for mine if you use this code. I also Italicized my comments in the code.

Option Explicit
Private mrsLogin As ADODB.Recordset
Private mcnLogin As ADODB.Connection
Private Const CONNECTION_STRING As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=J:\PTO\PTO.mdb;Mode=ReadWrite;Persist Security Info=False"

'This function attempts to log in the user when they submit their username and password.
Private Sub btnSubmit_Click()
'Declaration of Variables
Dim strSQL As String
Dim strUsername As String

'This section loads a new connection to the database.
Set mcnLogin = New ADODB.Connection
Set mrsLogin = New ADODB.Recordset

strSQL = ""
strSQL = "SELECT * FROM Passwords"
mrsLogin.Open strSQL, mcnLogin, adOpenDynamic, adLockPessimistic

'This If/Else statement verifies that the Username field has been filled in.
'If a value is entered, it starts the process of login verification.
If txtUsername.Text = vbNullString Then
lblMessage = "Please fill in the username before attempting to log in."
strUsername = txtUsername.Text

'This section searchs the database for a match with the username entered in by the user.
strUsername = "User_Name like '" & strUsername & "*'"
mrsLogin.Find strUsername, 0, adSearchForward, adBookmarkFirst

'This If/Else statement determines if the username was found in the database.
If mrsLogin.EOF Then
lblMessage = "Entry not found."
'This If/Else statement determines if the password entered by the user matches the password
'stored in the database for the desired username.
If mrsLogin.Fields("Password") = txtPassword.Text Then
lblMessage = "Incorrect password. Try again."
txtPassword = ""
End If
End If
End If
End Sub

11-13-2004, 07:26 AM
Thanks. That worked. I will get back to you if I need more help with this program.

11-13-2004, 08:48 AM
You really should implement one very important thing. You should store a Hash of the user's password and not the password in plain text. Check out this encryption thread ( for more information (look that the hash function.)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum