Problem with databases

Duskan
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

webbone
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.

Lars213
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
mcnLogin.Open CONNECTION_STRING

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."
Else
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."
Else
'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
frmEmployeeBalance.Show
Else
lblMessage = "Incorrect password. Try again."
txtPassword = ""
txtUsername.SetFocus
End If
End If
End If
End Sub

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

HardCode
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 (http://www.xtremevbtalk.com/showthread.php?t=31778) for more information (look that the hash function.)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum