Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB code for user login and password authentication

Status
Not open for further replies.

BillyBeefcake

Technical User
Jan 8, 2005
1
GB
Hi,

Any help with this problem is much appreciated..

I have a login page connected to an Access database. I need the code that will scan the database for the username and password combination and accept it.

I think I need a loop, or movenext and compare, but as I'm a complete noob with VB the variations Ive tried won't work and I've been banging my head against the wall!

Thanks for your time.
 
There are many possible variations on this but I'll make a few assumptions:

1. I'm assuming that you have an access table called Users containing user IDs and associated passwords. Other possibilities are things like using the Windows UserID or storing UserID/Password info in the registry. If you are doing those things then the following isn't what you want.

2. I'm also assuming that the user has typed a UserID and Password into controls on the form and you have saved those entered values in variables named UserID and PassWord respectively.

Given all that, you need to run something like
Code:
Dim rs  As DAO.Recordset
Dim SQL As String

SQL = "Select * From [Users] " & _
      "Where  [Users].[UserID]   = '" & UserID & "' AND " & _
      "       [Users].[Password] = '" & PassWord & "'"

Set rs = CurrentDB.OpenRecordset ( SQL )

If rs.EOF then
   [COLOR=green]' UserID, Password Does Not Exist.[/color]
Else
   [COLOR=green]' UserID, Password Were Found.[/color]
End If
 
any chance you could post your code for accessing the database from the v.b program
 
any chance you could post the code you are using to get the login page to aceess the database,cheers
 
I get a Run Time Error - "Object variable or With block variable not set". Set Rs = CurrentDb.OpenRecordset(SQL) is highlighted. What is wrong?

Private Sub Command1_Click()

txtuser = Text1.Text
txtpass = Text2.Text

SQL = "Select * From [Users] Where [Users].[username] = txtuser AND [Users].[password] = txtpass"

Set Rs = CurrentDb.OpenRecordset(SQL)

If Rs.EOF Then
MsgBox "Fel"
antalfel = antalfel + 1
Else
.....
End if

 
You need a "declaration" of the database. For the instantation statement, the database needs to be a DAO data base. This further implies a reference to the library supporting the database type. In most instances, today, this would be DAO 3.5 (or greater). Since you needed to ask the question to begin with I expect this to not actually seem like a complete answer to you. The terms in [b[BOLD[/b] (except the last one -of course) are appropiate key words for the help system.




MichaelRed


 
Check this thread:

VB/Access Password checkup
thread709-1044244

Tony00
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top