Solved

Using MS Access security via vb code

Posted on 1998-07-23
2
178 Views
Last Modified: 2010-05-03
I am currently using a secured ms access database and opening it within my vb application using a user name and password. I now want to know how can I create, modify & delete new users from the system.mda file using vb code and also have the capability to change password.
0
Comment
Question by:pcorreya
2 Comments
 
LVL 9

Accepted Solution

by:
Dalin earned 200 total points
ID: 1466490
pcorreya,
Try the following code. Let me know if you have any problems.
Regards
Dalin



const ADMIN_USERNAME = "Admin"
const ADMIN_PASSWORD = "adminpass (or whatever)"
const SHOWICON_STOP = 16



Function CreateNewUser% (ByVal username$, ByVal password$, ByVal PID$)

       '     '- create a new user.
       '     '- username$ - name
       '     '- password$ - user password
       '     '- PID$ - PID of user
       '     '-----------------------------------
       Dim NewUser As User
       Dim admin_ws As WorkSpace
       '     '=====================================
       '     '- check PID

              If (Len(PID$) < 4 Or Len(PID$) > 20) Then
                     MsgBox "Invalid PID", SHOWICON_STOP
                     CreateNewUser% = True
                     Exit Function
              End If

       '     '- verify that user does not yet exist

              If (UserExist%(username$)) Then
                     CreateNewUser% = True
                     Exit Function
              End If

       '     '- open new workspace and database as admin
       dbEngine.Workspaces.Refresh
       Set admin_ws = dbEngine.CreateWorkspace("TempWorkSpace",
        ADMIN_USER, ADMIN_PASSWORD)

              If (Err) Then
                     '     '- failed opening workspace
                     MsgBox "invalid administrator password", SHOWICON_STOP
                     MsgBox "Error: " & Error$, SHOWICON_STOP, SystemName
                     CreateNewUser% = True
                     Exit Function
              End If

       On Error Resume Next
       '     '- create the new user
       Set NewUser = admin_ws.CreateUser(username$, PID$, password$)

              If (Err) Then
                     MsgBox "Can't create new user.", SHOWICON_STOP
                     MsgBox Error$, SHOWICON_STOP
                     GoTo CreateNewUser_end
              End If

       '     '- add user to user list
       admin_ws.Users.Append NewUser
       '     '- add user to "Users" group
       Set NewUser = admin_ws.CreateUser(username$)
       admin_ws.Groups("Users").Users.Append NewUser
       admin_ws.Users(username$).Groups.Refresh
       admin_ws.Close
       CreateNewUser% = False
       CreateNewUser_end:
       On Error GoTo 0
End Function

0
 
LVL 1

Author Comment

by:pcorreya
ID: 1466491
Dalin

I failed to tell you that I was using VB 3, will this work.
I tried looking for the workspace object, but couldn't find it
in vb 3.

By the way what is PID, how do you get this.

Bye
Patrick
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now