UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Validating User Credentials On Command Button, Office 2007    
 
   
JOEB1
post Apr 17 2012, 09:58 AM
Post #1

UtterAccess Member
Posts: 21



Hi All,

I have created a SplashScreen user login form with two test boxes, one for Employee Name and the other for Password. I also created a Command button to Enter. I then created an Employees table with three fields, ID, EmployeeName, and Password.

How can I get the Command button to validate the Employee Name and associated Password are in the table when the user clicks the button? Then have either an error message if the entry does not match or grant the user access to the application if the login information is correct.

Thanks very much for you help.
Joe B.
Go to the top of the page
 
+
theDBguy
post Apr 17 2012, 10:01 AM
Post #2

Access Wiki and Forums Moderator
Posts: 48,598
From: SoCal, USA



Hi Joe,

(IMG:style_emoticons/default/welcome2UA.gif)

You could try something like:

If Me.PasswordTextboxName = DLookup("PasswordFieldName", "EmployeesTableName", "EmployeeNameField='" & Me.EmployeeNameTextbox & "'") Then
MsgBox "Welcome!"
Else
MsgBox "Sorry..."
End If

Just my 2 cents... (IMG:style_emoticons/default/2cents.gif)
Go to the top of the page
 
+
JOEB1
post Apr 17 2012, 01:34 PM
Post #3

UtterAccess Member
Posts: 21



Thanks. I entered this, If Me.PasswordTextboxName = DLookup("PasswordFieldName", "EmployeesTableName", "EmployeeNameField='" & Me.EmployeeNameTextbox & "'") Then
MsgBox "Welcome!"
Else
MsgBox "Sorry..."
End If

as an event procedure on the "On Click" but when the command button is clicked nothing happens. Any thoughts?

Thanks for your help as this problem has been driving me crazy.
Go to the top of the page
 
+
theDBguy
post Apr 17 2012, 01:46 PM
Post #4

Access Wiki and Forums Moderator
Posts: 48,598
From: SoCal, USA



Hi Joe,

Is your DB placed in a Trusted Location?

Just my 2 cents... (IMG:style_emoticons/default/2cents.gif)
Go to the top of the page
 
+
JOEB1
post Apr 17 2012, 01:51 PM
Post #5

UtterAccess Member
Posts: 21



I put the DB in a trusted location then clicked the button and received this error: Compile Error: Method or Data member not found
Go to the top of the page
 
+
theDBguy
post Apr 17 2012, 01:54 PM
Post #6

Access Wiki and Forums Moderator
Posts: 48,598
From: SoCal, USA



Hi,

Glad to hear you're making good progress. Next step is to replace all the placeholder names I used in my example with the actual names of the fields in your table and controls on your form.

Just my 2 cents... (IMG:style_emoticons/default/2cents.gif)
Go to the top of the page
 
+
JOEB1
post Apr 17 2012, 02:15 PM
Post #7

UtterAccess Member
Posts: 21



The Name of the Table is Employees with these fields, EmployeeName and Password. The text boxes are named Password and EmployeeName. So then would the correct code be:
If Me.Password= DLookup("Password", "Employees", "EmployeeName='" & Me.EmployeeName & "'") Then
MsgBox "Welcome!"
Else
MsgBox "Sorry..."
End If

Go to the top of the page
 
+
Tiesto_X
post Apr 17 2012, 02:28 PM
Post #8

UtterAccess Veteran
Posts: 330



(IMG:style_emoticons/default/welcome2UA.gif)

CODE
If Nz(Me.Username, "") = "" Then
        MsgBox "Enter user ID!", 48, "ID"
        Me.Username.SetFocus
        Exit Sub
    End If

    If Nz(Me.Password, "") = "" Then
        MsgBox "Enter user Password", 48, "Password"
        Me.Password.SetFocus
        Exit Sub
    End If

    If Me.Password <> Me.Username.Column(1)
        MsgBox "Password is wrong. Try again.", 48, "Error"
        Me.Password.SetFocus
    Else
        Me.Visible = False
        DoCmd.OpenForm "FormName"
    End if


This works only if u use Username as Combobox not as textbox...

HTH's

This post has been edited by Tiesto_X: Apr 17 2012, 02:37 PM
Go to the top of the page
 
+
theDBguy
post Apr 17 2012, 02:45 PM
Post #9

Access Wiki and Forums Moderator
Posts: 48,598
From: SoCal, USA



QUOTE (JOEB1 @ Apr 17 2012, 12:15 PM) *
The Name of the Table is Employees with these fields, EmployeeName and Password. The text boxes are named Password and EmployeeName. So then would the correct code be:
If Me.Password= DLookup("Password", "Employees", "EmployeeName='" & Me.EmployeeName & "'") Then
MsgBox "Welcome!"
Else
MsgBox "Sorry..."
End If

Yes, give that a shot and let us know what happens. Also, I was assuming that the form and the textboxes are not bound to the Employees table, correct?

Just my 2 cents... (IMG:style_emoticons/default/2cents.gif)
Go to the top of the page
 
+
JOEB1
post Apr 17 2012, 02:51 PM
Post #10

UtterAccess Member
Posts: 21



It worked!!! DB Guy, Thanks for all your help!!!
Go to the top of the page
 
+
theDBguy
post Apr 17 2012, 02:51 PM
Post #11

Access Wiki and Forums Moderator
Posts: 48,598
From: SoCal, USA



QUOTE (Tiesto_X @ Apr 17 2012, 12:28 PM) *
This works only if u use Username as Combobox not as textbox...

Just wanted to comment on the decision to use a Combobox or a Textbox. Some developers prefer to use the Combobox to make it easier to select the user's login name. Others, me included, prefer to use a Textbox because the purpose of the login form is to verify the credentials of the user attempting to access the database. If they are able to "select" a username from a dropdown, then they are halfway through the door. They just need to guess the password to get in. But, if they have to enter the username in a textbox, then they will have to guess both the username and the matching password to get in.

Just a matter of personal preference, really. And, how much you want the user to work hard on getting into the database.

Just my 2 cents... (IMG:style_emoticons/default/2cents.gif)
Go to the top of the page
 
+
theDBguy
post Apr 17 2012, 02:52 PM
Post #12

Access Wiki and Forums Moderator
Posts: 48,598
From: SoCal, USA



Hi Joe,

QUOTE (JOEB1 @ Apr 17 2012, 12:51 PM) *
It worked!!! DB Guy, Thanks for all your help!!!

(IMG:style_emoticons/default/yw.gif)

Tiesto and I are happy to help. Good luck with your project.
Go to the top of the page
 
+
Tiesto_X
post Apr 17 2012, 05:00 PM
Post #13

UtterAccess Veteran
Posts: 330



Hi there,

theDBguy very thanks for your easiest solution!

You are right, always here to help! (IMG:style_emoticons/default/smile.gif)
Go to the top of the page
 
+
theDBguy
post Apr 17 2012, 05:05 PM
Post #14

Access Wiki and Forums Moderator
Posts: 48,598
From: SoCal, USA



Hi Tiesto,

Cheers (IMG:style_emoticons/default/cheers.gif)
Go to the top of the page
 
+
tylerpestell
post Apr 18 2012, 03:00 AM
Post #15

UtterAccess Enthusiast
Posts: 76



So are you saving the passwords in the table as plain text? Shouldn't you use some sort of encryption like MD5 before you save them in the database? It just seems like really bad practice to be storing your users passwords in plain text.
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 18th June 2013 - 10:35 PM