help with coding - for creating secure login forms

V

vandy

Hi All,

I have been doing some search on this topic and require some coding help.

I want to create a login form which checks for username, pwd and
securitylevel and accordingly give access to certain queries , forms and
reports. I do not want to use the Access user level security wizard and want
to create a separate security module.

I have come across this code posted by Klatuu which is probably the solution
i am looking for.

Public Function SetSecurityProp(UserInitials As String, SecurityLevel As
Integer) As Boolean
Dim prp As Property
Const conPropNotFound As Integer = 3270

On Error GoTo ErrorSetSecurityProp
' Explicitly refer to Properties collection.
CurrentDb.Properties("User") = UserInitials
CurrentDb.Properties.Refresh
CurrentDb.Properties("SecurityLevel") = SecurityLevel
CurrentDb.Properties.Refresh
SetSecurityProp = True

ExitSetSecurityProp:
Exit Function

ErrorSetSecurityProp:
If Err = conPropNotFound Then

' Create property, denote type, and set initial value.
Set prp = CurrentDb.CreateProperty("User", dbText, UserInitials)
' Append Property object to Properties collection.
CurrentDb.Properties.Append prp
CurrentDb.Properties.Refresh
Set prp = CurrentDb.CreateProperty("SecurityLevel", dbInteger,
SecurityLevel)
' Append Property object to Properties collection.
CurrentDb.Properties.Append prp
CurrentDb.Properties.Refresh
SetSecurityProp = True
Resume ExitSetSecurityProp
Else
MsgBox Err & ": " & vbCrLf & Err.DESCRIPTION
SetSecurityProp = False
Resume ExitSetSecurityProp
End If

End Function

Function ChangeProperty(strPropName As String, varPropType As Variant,
varPropValue As Variant) As Integer
Dim dbs As Object, prp As Variant
Const conPropNotFoundError = 3270

Set dbs = CurrentDb
On Error GoTo Change_Err
dbs.Properties(strPropName) = varPropValue
ChangeProperty = True

Change_Bye:
Exit Function

Change_Err:
If Err = conPropNotFoundError Then ' Property not found.
Set prp = dbs.CreateProperty(strPropName, _
varPropType, varPropValue)
dbs.Properties.Append prp
Resume Next
Else
' Unknown error.
ChangeProperty = False
Resume Change_Bye
End If
End Function


I want to know how to implement this. What is the table i should create and
should i use this code as a module and how and were to call it.

How to implement case SecurityLevel =1
open form A
query A

case SecurityLevel =2
open form b

etc...

Would really appreciate if someone can help me out with this. I am not too
much of a progammer but i am willing to learn.
 
J

John W. Vinson

Would really appreciate if someone can help me out with this. I am not too
much of a progammer but i am willing to learn.

Well...

You're taking on a task that some very advanced programmers have found to be
very challenging indeed.

Security systems are DIFFICULT. It's hard to make such a system which is a)
effective at keeping the guys in black hats out while still b) not making life
miserable for the guys in white hats. Essentially any "home grown" security
system will be vulnerable to attack; Access workgroup security can be hacked
with a bit of effort and perhaps a google search; even SQL/Server security can
be broken, though with much more difficulty.

The analogy I'd use is to door locks on your house. If you need real security,
you can put in double-key locks, heavy duty bolt plates, etc. etc. - and the
burglar can still throw a rock through the picture window. If you want to
reliably keep anyone out, you need a concrete bunker... and then it's not a
house any more. "Locks keep honest people out"!

If you're trying to just direct honest employees to the right section of the
application, homegrown security can be useful. If you're trying to block a
skilled and intelligent user from intentionally breaking through your system
and accessing data they shouldn't....good luck; you'll need it.

John W. Vinson [MVP]
 

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

Similar Threads

AllowByPassKey 6
set dbs = another database? 5
Error 429 in Runtime 0
Run-time error 3
Dual startup - needs refresh? 1
Calculator.. type mismatch error when closing? 10
Bypass shift key 0
Disable ByPass Key 7

Top