User Security Levels and Password login screen (1 Viewer)

G

goldie12

Guest
Does anyone have any sample code or a sample database?

I'm looking for a login form that has security level and passwords.

thanx
 

whitesmoke

Registered User.
Local time
Yesterday, 19:05
Joined
Jun 23, 2006
Messages
29
do you want login screen based on ms access login, which is a hassle to do or a login based on a table with usernames?
 
G

goldie12

Guest
a login based on a table with usernames and security levels too.

thanx
 

whitesmoke

Registered User.
Local time
Yesterday, 19:05
Joined
Jun 23, 2006
Messages
29
here is the code i've used.. create a login screen with 2 text boxes (txtpass and txtname and an enter/login button on click event enter below. (of course have a users table to open.. work with it...

-- code for Click event of cmdEnter_Click()
Public Sub cmdEnter_Click()
Dim rst As dao.Recordset
Dim strSQL As String

'-- test username given, exit sub if not
If Nz(txtname) = "" Then
MsgBox "You must enter a name", vbInformation, "No Name Entered"
txtname.SetFocus
Exit Sub
End If

'-- test password given, exit sub if not
If Nz(txtPass) = "" Then
MsgBox "You must enter a password", vbInformation, "No Password Entered"
txtname.SetFocus
Exit Sub
End If

'-- create query to get record for specifed username
strSQL = "SELECT [FIRSTNAME], [LASTNAME], [SecretCode],[Security],[LOGINID] FROM [tUSERS] WHERE [LOGINID]='" & txtname & "';"

'-- run query
Set rst = CurrentDb.CreateQueryDef("", strSQL).OpenRecordset

'-- test if record found for given username, if not; incorrect username given
If Not rst.EOF Then

'-- test if password matches password in users record
If rst("SecretCode") = txtPass Then
DoCmd.OpenForm "frmMenu"
DoCmd.Close acForm, "frmLogin"
'-- correct password! now determine accesslevel, and open correct form
Else

'-- code to handle incorrect password
MsgBox "Password incorrect. Please try again...." & intLogonAttempts, vbExclamation, "Password orrect"
txtPass.SetFocus
End If
Else

'-- code to handle invalid username
MsgBox "Invalid UserName given. Please Try Again...." & intLogonAttempts, vbExcalamation, "Invalid UserName"
txtname.SetFocus
End If

'-- close up recordset object
rst.Close
Set rst = Nothing

'-- and finally, increment the logon attempt counter, quit access after 3 attempts!
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If


'--Close Login Form
 

whitesmoke

Registered User.
Local time
Yesterday, 19:05
Joined
Jun 23, 2006
Messages
29
FYI: this test for case sensivity in the password only.
 

hotciats

New member
Local time
Today, 10:05
Joined
Oct 17, 2010
Messages
5
hello whitesmoke. in your example above, what exactly are the names of the fields in the user tables so that i can relate it in your codes. i am still new in vb and i can't determine what are constants and variables in it.

for example in this particular code placed in "[ ]", what should be the names of the field in the user tables should be made?

strSQL = "SELECT [FIRSTNAME], [LASTNAME], [SecretCode],[Security],[LOGINID] FROM [tUSERS] WHERE [LOGINID]='" & txtname & "';"

thanks in advance.
 

Users who are viewing this thread

Top Bottom