Advanced Login Controls - Can you help?

G

Guest

Thank you for taking the time to read my post regardless of whether you can
help or not.

I am trying to set up a user control form which will allow users to access
the application but only with the right registered password per user. Each
user has there own password, i am aware of how to set up controls and so on
for this and have created the code to make this work.

However there is a few enhancements i'd love to add.

1. Allows users only 3 attemps to try and login before the application closes.
2. As the user makes and error (enters the wrong password) a warning mesage
box appears telling them how many attempts they have left (each error means a
message box which counts down the number of attempts left)

I have tried to do "Loops" and "Do" btu am still a novice to vba.

Please find my code below as follows.



Private Sub btnLoginOk_Click()


If IsNull(txtUserName) Or txtUserName.Value = "" Then

MsgBox "Please enter your user name.", vbQuestion + vbOKOnly, "Campaign
Manager"

Exit Sub

End If


If IsNull(txtPassword) Or txtPassword.Value = "" Then

MsgBox "Please enter your password.", vbQuestion + vbOKOnly, "Campaign
Manager"

Exit Sub

End If

If DCount("[username]", "[tblUsers]", "[username]=txtUsername.Value") = 1 Then

currentuser = txtUserName.Value

If txtPassword = DLookup("[password]", "[tblUsers]",
"[username]=txtUsername.Value") Then

If DLookup("[inactive]", "[tblUsers]",
"[username]=txtUsername.Value") = True Then

MsgBox "Your account has been locked. Please contact the
administrator.", vbCritical + vbOKOnly, "Campaign Manager"

Else

DoCmd.OpenForm "frmMain"

With Application.Forms.frmMain.lblusernamewelcome
.Caption = "Welcome! " & UCase(Left(currentuser, 1)) &
Mid(currentuser, 2, 30)
End With

DoCmd.Close acForm, "frmLogin"

End If

Else

MsgBox "Password Incorrect! Please Try Again...", vbCritical + vbOKOnly,
"Campaign Manager"

End If

Else

MsgBox "The specified user name does not exist!", vbExclamation + vbOKOnly,
"Campaign Manager"

End If

End Sub
 
D

DubboPete

Hello Mr Access to Access,

I have this solution in code in a database at work, but won't be there for
eight hours....

I have also added the option to do the 'forgot password?' thing too!

So, if you don't get an answer within that time, I shall send you the code
that I use...

DubboPete
 
D

DubboPete

And, you will get lots of messages today about security - or lack of it! I
did.....

DubboPete
 
G

Guest

You are a star! Thank you for your help. I look forward to seeing your code...

Regards

DubboPete said:
And, you will get lots of messages today about security - or lack of it! I
did.....

DubboPete

Access To Access said:
Thank you for taking the time to read my post regardless of whether you
can
help or not.

I am trying to set up a user control form which will allow users to access
the application but only with the right registered password per user. Each
user has there own password, i am aware of how to set up controls and so
on
for this and have created the code to make this work.

However there is a few enhancements i'd love to add.

1. Allows users only 3 attemps to try and login before the application
closes.
2. As the user makes and error (enters the wrong password) a warning
mesage
box appears telling them how many attempts they have left (each error
means a
message box which counts down the number of attempts left)

I have tried to do "Loops" and "Do" btu am still a novice to vba.

Please find my code below as follows.



Private Sub btnLoginOk_Click()


If IsNull(txtUserName) Or txtUserName.Value = "" Then

MsgBox "Please enter your user name.", vbQuestion + vbOKOnly, "Campaign
Manager"

Exit Sub

End If


If IsNull(txtPassword) Or txtPassword.Value = "" Then

MsgBox "Please enter your password.", vbQuestion + vbOKOnly, "Campaign
Manager"

Exit Sub

End If

If DCount("[username]", "[tblUsers]", "[username]=txtUsername.Value") = 1
Then

currentuser = txtUserName.Value

If txtPassword = DLookup("[password]", "[tblUsers]",
"[username]=txtUsername.Value") Then

If DLookup("[inactive]", "[tblUsers]",
"[username]=txtUsername.Value") = True Then

MsgBox "Your account has been locked. Please contact the
administrator.", vbCritical + vbOKOnly, "Campaign Manager"

Else

DoCmd.OpenForm "frmMain"

With Application.Forms.frmMain.lblusernamewelcome
.Caption = "Welcome! " & UCase(Left(currentuser, 1)) &
Mid(currentuser, 2, 30)
End With

DoCmd.Close acForm, "frmLogin"

End If

Else

MsgBox "Password Incorrect! Please Try Again...", vbCritical +
vbOKOnly,
"Campaign Manager"

End If

Else

MsgBox "The specified user name does not exist!", vbExclamation +
vbOKOnly,
"Campaign Manager"

End If

End Sub
 

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