Log in user name and password

rkaria

Registered User.
Local time
Today, 08:06
Joined
Nov 19, 2009
Messages
48
Hi
I have set up a form and a table for users to enter there user name and password.

I have set the table with 2 user names and passwords to go with them. How ever when the I enter the users name and password the first one works, but the second one says invalid. even though I know I have entered it correctly.

I tried creating 2 more users and again only the first one works.

The coding I have used is below. Can any see why it is only accepting the first entry.

'Check to see if data is entered into the UserName

If IsNull(Me.username) Or Me.username = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.username.SetFocus
Exit Sub
End If
'Check to see if data is entered into the password box

If IsNull(Me.password) Or Me.password = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.password.SetFocus
Exit Sub
End If

'check if username and password matches with the ones in the table

If Me.password.Value = DLookup("Password", "login") And Me.username.Value = DLookup("user", "login") Then


DoCmd.Close acForm, "frmLogin", acSaveNo
DoCmd.OpenForm "Opening form"
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
"Invalid Entry!"
Me.password.SetFocus
End If


Thanks
rjkaria
 
Lookup the proper syntax for DLookup, your not applying it correctly it is a 3 part statement
 
try;

If Me.password.Value = DLookup("Password", "login", "[username]='" & Me.username.Value & "'") And _
Me.username.Value = DLookup("username", "login", "[username]='" & Me.username.Value & "'") Then
 
try;

If Me.password.Value = DLookup("Password", "login", "[username]='" & Me.username.Value & "'") And _
Me.username.Value = DLookup("username", "login", "[username]='" & Me.username.Value & "'") Then


Thank you but that has not made any difference
 
Sorry

test please:

Dim xlog As Variant
If xlog = DLookup("[Password]", "login", "[Password]='" & Me.Password & "' And [username]='" & Me.UserName & "'") Then
 
I use Access 2000 and do the following which works great:

**********MODULE********** (called LogIn with following coding)

Option Compare Database
Option Explicit

Public lngMyEmpID As Long
' Below moved to Gloval Variables Module
' Global intLogonAttempts As Integer
Public lngMyLogInID As Long

**********MODULE********** (called GlobalVariables, which includes following coding for use with my log in form, but as above could include it in the LogIn module)

Global intLogonAttempts As Integer

**********TABLE********** (User Name and Password table called - tblEmployees)

There are three Name Fields:

lngEmplID Data Type: AutoNumber
Field Size: Long Integer
New Values: Increment
Indexed: Yes(No Duplicates)

strEmpName Data Type: Text
Field Size: 50
Required: No
Allow Zero Length: No
Indexed: No
Unicode Compression: Yes

strEmplPassword Data Type: Text
Field Size: 20
Input Mask: Password
Required: No
Allow Zero Length: No
Indexed: No Unicode Compression: Yes

**********LOG IN FORM**********

On my log in form I have two labels, a combo box, a text box, and a command button (I use a picture graphic for the command button which shows a button with the word ENTER on it)

There is a label ("lblEmployeeName") with text "User Name:" followed by a combo box ("cmbxEmployeeName"). This is coded to allow either to begin typing in an Employee/User Name so auto fills or by the Employee/User Name by selecting with the drop down of the comb box (names from the table), with following coding:

Format Tab (below coding plus my formatting - ensure width of comb box is sufficient for longest Employee/User Name to fully appear) :

Decimal Places: Auto
Column Count: 3
Column Heads: No
Column Widths: 0";1";0"
List Rows: 6
List Width: Auto
Visible: Yes
Display When: Always

Data Tab:

Row Source Type: Table/Query
Row Source: SELECT [tblEmployees].[lngEmpID], [tblEmployees].[strEmpName], [tblEmployees].[strEmpPassword] FROM tblEmployees ORDER BY [tblEmployees].[strEmpName];
Bound Column: 1
Limit to List: Yes
Auto Expand: Yes
Enabled: Yes
Locked: No

Event Tab:

After Update - Event Procedure/Code

Private Sub cmbxEmployeeName_AfterUpdate()

'After selecting user name set focus to password field
Me.txtPassword.SetFocus

End Sub

On Not in List - Event Procedure Code

Private Sub cmbxEmployeeName_NotInList(NewData As String, Response As Integer)

MsgBox "Please re-enter.", vbCritical, "User Name Not in List!"
Me.cmbxEmployeeName = ""
Me.cmbxEmployeeName.SetFocus

End Sub

Then below that is a label ("lblPassword") with the text "User Password:" followed by a text box ("txtPassword") with PASSWORD Input Mask, for them to type in the password - ensure the width of the text box is sufficient for longest possible password - strEmplPassword Text Size.

For the All Tab for textPassword:

Allow Auto Correct: Yes
Enabled: Yes
Locked: No
Filter Lookup: Database Default

I then use the Enter command button to check the two fields, including case sensitive password check. This allows use of upper and lower case and special keys (such as $%^&*() etc.) in the password.

Private Sub btnEnter_Click()

'Check to see if User Name entered in combo box

If IsNull(Me.cmbxEmployeeName) Or Me.cmbxEmployeeName = "" Then
MsgBox "You must enter a User Name.", vbCritical, "User Name Missing!"
Me.cmbxEmployeeName.SetFocus
Exit Sub
End If

'Check to see if data is entered into the User Password box

If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter User's Password.", vbCritical, "User Password Missing!"
Me.txtPassword.SetFocus
Exit Sub
End If

' Verification of case-sentive password data
Dim i As Integer
Dim Counter As Integer
Counter = 0

' Start of GTS verification code
If cmbxEmployeeName.Column(2) = txtPassword Then
For i = 1 To Len(txtPassword)
If Asc(Mid(cmbxEmployeeName.Column(2), i)) <> Asc(Mid(txtPassword, i)) Then
Counter = Counter + 1
End If
Next
Else
Counter = 1
End If
If Counter < 1 Then
MsgBox "Password Verified.", vbExclamation, "Password Verification Successful!"
gsEmployeeName = cmbxEmployeeName.Column(1) 'NOTE - I use the global variable called gsEmployeeName for use by another module to record in a different table use of subforms by an Employee/User, so should delete from coding
Me.Parent.MainMenu.SourceObject = "fMainForm1_MainMenu_SubForm" 'NOTE: I use a Main Form and load Subforms into and out of the Main Form; if you use Form to Form, then use the coding to load your next Form
Else
MsgBox "Please Re-Enter Password.", vbCritical, "Password Verification Failed!"
Me.txtPassword = ""
Me.txtPassword.SetFocus
End If
' End of GTS verification code

'If User Enters incorrect password 3 times database will shutdown

intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "Security Block: Too Many Attempts to Log In - Program Locked! You do not have access to this database. Please contact your program administrator. Program will close.", vbCritical, "Entry Prohibited!"
Application.Quit
End If

End Sub

For the Form:

All Tab:

Record Source: tblEmployees
Allow Filters: Yes
Default View: Single View
Views Allowed: Both
Allow Edits: Yes
Allow Additions: Yes
Allow Deletions: Yes
Data Entry: No
Recordset Type: Dynaset
Record Locks: All Records
Record Selectors: No
Navigation Buttons: No
Dividing Lines: No
Auto Resize: Yes
Auto Center: No
Pop Up: No
Modal: No
Cycle: All Records
Has Module: Yes
All Design Changes: Design View Only

*****
Hope this helps.
 
Last edited:
This is simple, but it works for me:
Create a Table (ie "Users") with ID, Name Password columns.
Create a small form that will accept and password entries typed into an unbound textbox called "Password".
Place the following code behind the "BeforeInsert" event:
==============

Private Sub Form_BeforeInsert(Cancel As Integer)
'To avoid problems if the filter matches no records, we did not set its AllowAdditions to No.
'Prevent new records by canceling the form's BeforeInsert event instead.
Cancel = True
MsgBox "Adding new users is a DBase Administrator function.", vbInformation, "Access denied."
End Sub

==================

Now, Create a "Login" button on the small form, and
Place the following Event Procedure behind the button's OnClick event:
Note: I have commented out the username portion of the code because I don't use it.
====================

Private Sub Login_Click()

Dim ID As Long
Static intLogonAttempts As Integer

'Check to see if data is entered into the UserName combo box

' If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
' MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
' Me.cboEmployee.SetFocus
' Exit Sub
' End If

'Check to see if data is entered into the password box

If IsNull(Me.Password.Value) Or Me.Password.Value = "" Then
MsgBox "A Valid password is required. Three (3) unsuccessful login attempts will shutdown the database.", vbOKOnly, _
"Login Warning!"
Me.Password.SetFocus

Exit Sub

End If

'Check for the value of [Password] in [Users] table to see if this matches what's typed in

If Me.Password.Value = DLookup("[Password]", "Users", "[Password] ='" _
& Forms!Login!Password & "'") Then

'Close Login and open YourFormNameHere

DoCmd.OpenForm "YourFormNameHere"
DoCmd.Close acForm, "Login", acSaveNo

Else
MsgBox "Password not on file. Try again, or contact the Database Administrator." & Chr(13) & "Reminder: Passwords are case sensitive.", vbOKOnly, _
"Login Error!"
Me.Password.SetFocus
End If

'If User Enters incorrect password 3 times database will shutdown
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then

MsgBox "Login Unsuccessful! Database shutdown initiated." & Chr(13) & "Contact Database Adminstrator.", _
vbCritical, "Access Denied - Database restart required!"

DoCmd.CloseDatabase
End If

End Sub
===============

Try it and let me know!
 

Users who are viewing this thread

Back
Top Bottom