Log-In Screen with UserName and Password

A

ant1983

Hi,

I'd like my db to prompt the user for his username and password. Table
structure as follows:

tblUsers
- autUserID (Autonumber and Pri Key)
- txtName
- txtUserName
- txtPassword

I have a unbound form with the following:

frmUserName
- txtUserName (Unbound text box)
- txtPassword (Unbound text box)
- cmdOK (Button opening frmMainMenu where all other buttons are located

So what i want to do is for my db to check if the username and password are
correct and then if it is to carry on opening the frmMainMenu but if it isnt
then it prompts u.

How do i do this?

:)

Ta
 
J

Jeanette Cunningham

Hi,
put an OK and a Cancel button on the form with the text box for user name
and password
The cancel button closes down the application.
The OK button checks that the user name has been entered and shows a message
if not.
The Ok button checks that the password matches the stored password for that
user.
If they match, the OK button opens up the main menu of the database.
If they don't match the OK button shows a message and asks the user to try
again.
You might like to limit the number of successful tries before you code to
close the application.
I believe there is an example of a login form on Jeff Conrad's website,
sorry I don't have the link for you.
He also calls himself an Access junkie.


Jeanette Cunningham -- Melbourne Victoria Australia
 
D

DaveT

Jeanette's advice is good: max tries, etc

Assume UserName is not case sensitive, but password is.

To check password use something like:

If StrComp(strEntered, strValidPassword, vbBinaryCompare) <> 0 Then
'increment your password attemps
'if max tries has been reached, tell user and bail out (for example:
DoCmd.Quit )

MsgBox "Try password again", vbExclamation, ""
txtPassword = Null
txtPassword.SetFocus
'increment your password attemps
Exit Sub

Else

'success action such as open Main Menu, etc


End If
 
F

Frank

You might like to also consier this -

Private Sub cmdOK_Click()

Static bytFailedAttempts As Byte

If StrComp(txtPassword, DLookup("strPassword", "tblOperators",
"strOperator = """ & txtOperator & """"), vbBinaryCompare) = 0 Then
' open Main Menu
MsgBox "Open Main Menu"
' close logon form
DoCmd.Close acForm, Name
Else
bytFailedAttempts = bytFailedAttempts + 1
If IsNull(DLookup("strOperator", "tblOperators", "strOperator = """
& txtOperator & """")) Then
If bytFailedAttempts = 3 Then
MsgBox "Maximum logon attempts exceeded."
' close logon form
DoCmd.Close acForm, Name
Else
txtOperator = Null
txtPassword = Null
txtOperator.SetFocus
MsgBox "Unknown Operator ( " & 3 - bytFailedAttempts & "
logon attempt" & IIf(bytFailedAttempts = 1, "s", "") & " remaining )."
End If
Else
If bytFailedAttempts = 3 Then
MsgBox "Maximum logon attempts exceeded."
' close logon form
DoCmd.Close acForm, Name
Else
txtPassword = Null
txtPassword.SetFocus
MsgBox "Incorrect Password ( " & 3 - bytFailedAttempts & "
logon attempt" & IIf(bytFailedAttempts = 1, "s", "") & " remaining )."
End If
End If
End If

End Sub

Assumes -
.. a form with textbox "txtOperator" and textbox "txtPassword" and command
buttons "cmdOK" and "cmdExit"; and
.. a table "tblOperators" with text fields "strOperator" and "strPassword"
(and at least one row of data).

You might also think about disabling cmdOK until something is entered into
"txtOperator" and "txtPassword" or, better yet, getting rid of cmdOK
altogether and firing off the code in the AfterUpdate event of each of
"txtOperator" and "txtPassword" (but only if both fields are not Null).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top