Solved

Using MS Access security via vb code

Posted on 1998-07-23
2
165 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

746 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

13 Experts available now in Live!

Get 1:1 Help Now