Avatar billede dougheffernan Nybegynder
25. oktober 2002 - 10:52 Der er 38 kommentarer og
1 løsning

Sikkerhed i Access: Skifte adgangskode

Kort fortalt:
Jeg har brugt guiden Sikkerhed til at oprette 3 grupper med nogle brugere i hver.
Som min database er nu, får alm. brugere ikke vist værktøjslinier eller menuer, men skal alligevel have adgang til at skifte adgangskode. Dette tænker jeg implementeret via 3 tekstbokse og en Ok knap på en formular. Problemet er: Hvordan skal sådan noget VBA kode se ud, for at kunne skifte adgangskode i arbejdsgruppeoplysningsfilen?
Avatar billede dougheffernan Nybegynder
25. oktober 2002 - 10:54 #1
Jeg kan se at jeg skal bruge noget Workspace, User og Group....men hvordan...?
Avatar billede terry Ekspert
25. oktober 2002 - 11:01 #2
Sub ChangePasswords()  Dim ws As Workspace, usr As User  ' Add passwords to the Admin, OrdersAdmin, and OrdersOwner  ' user accounts.  Set ws = DBEngine.Workspaces(0)  ws.Users("Admin").NewPassword "", "AdminPwd"  ws.Users("OrdersAdmin").NewPassword "", "OrdAdminPwd"  ws.Users("OrdersOwner").NewPassword "", "OrdOwnerPwd"  ' Create a user account, specifying a PID and a password with  ' the CreateUser method.  Set usr = ws.CreateUser("Tim Smith", "ilmj2d", "MyPwd")  ws.Users.Append usr  ' Create a user account, specifying a password with the  ' Password property.  Set usr = ws.CreateUser("Robert King")  usr.PID = "tdi3tcm"  usr.Password = "NewUserPwd"  ws.Users.Append usrEnd Sub
Avatar billede dougheffernan Nybegynder
25. oktober 2002 - 11:01 #3
Har fundet et eksempel i hjælpefilen, hvis det kan bruges lukker jeg spørgsmålet igen.
Avatar billede dougheffernan Nybegynder
25. oktober 2002 - 11:01 #4
Nå, Terry var godt nok hurtig, kigger lige på det, Terry, og melder tilbage...
Avatar billede terry Ekspert
25. oktober 2002 - 11:02 #5
Take a look at this link too
Avatar billede terry Ekspert
25. oktober 2002 - 11:03 #6
Avatar billede dougheffernan Nybegynder
25. oktober 2002 - 11:40 #7
I think your example would work GREAT, if it wasn't for this message:

Run-Time error '3033':
Du har ikke de nødvendige tilladelser til at bruge objektet "sys". Få systemadministrator eller den person, der oprettede dette objekt, til at give dig de nødvendige tilladelser.
Avatar billede dougheffernan Nybegynder
25. oktober 2002 - 11:41 #8
Debug sets the cursor at this line:
ws.Users(CurrentUser).NewPassword "", "test"
Avatar billede dougheffernan Nybegynder
25. oktober 2002 - 11:43 #9
I've deleted some of the lines from your example, here's the code I'm using:

Public Function ChangePassword()
  Dim ws As Workspace
  Dim usr As User
  Set ws = DBEngine.Workspaces(0)
  ws.Users(CurrentUser).NewPassword "", "test"
End Function
Avatar billede dougheffernan Nybegynder
25. oktober 2002 - 11:49 #10
What I want is for the CurrentUser to be able to change his password....how?
Avatar billede terry Ekspert
25. oktober 2002 - 12:06 #11
just out for lunch, will get back soon.
Avatar billede dougheffernan Nybegynder
25. oktober 2002 - 12:08 #12
ok
Avatar billede dougheffernan Nybegynder
25. oktober 2002 - 12:17 #13
This is what I got so far:

Public Function ChangePassword()
  Dim usr As User
  Dim strPassword As String
  Set usr = DBEngine(0).Users(CurrentUser)
  On Error Resume Next
  usr.NewPassword "", ""
  strPassword = InputBox("You Must Enter a Password Before Proceeding", "Enter Password")
  If strPassword = "" Then
    DoCmd.Quit
  Else
    usr.NewPassword "", strPassword
  End If
End Function

Private Sub Kommandoknap1_Click()
  ChangePassword
End Sub
Avatar billede dougheffernan Nybegynder
25. oktober 2002 - 12:30 #14
But it doesn't work, atleast the password isn't change or anything!
Avatar billede hossein Nybegynder
25. oktober 2002 - 12:52 #15
Måske den kan hjælpe dig:

Function SetDBPassword(strDBPath As String, _

                strOldPwd As String, _

                strNewPwd As String)

  ' This procedure sets a new password or changes an existing

  ' password.

  Dim dbsDB    As DAO.Database

  Dim strOpenPwd  As String

  ' Create connection string by using current password.

  strOpenPwd = ";pwd=" & strOldPwd



  ' Open database for exclusive access by using current password. To

  ' get exclusive access, you must set the Options argument to True.

  Set dbsDB = OpenDatabase(Name:=strDBPath, _

                    Options:=True, _

                    ReadOnly:=False, _

                    Connect:=strOpenPwd)

  ' Set or change password.

  With dbsDB

    .NewPassword strOldPwd, strNewPwd

    .Close

  End With

  Set dbsDB = Nothing

End Function
Eller kig:
http://www.microsoft.com/enable/download/products/office/opg/ch18.txt
Avatar billede terry Ekspert
25. oktober 2002 - 13:14 #16
Dim ws As Workspace, usr As User 
Set ws = DBEngine.Workspaces(0) 
ws.Users(CurrentUser).NewPassword "OldPassword", "NewPassword"
Avatar billede dougheffernan Nybegynder
28. oktober 2002 - 08:47 #17
Hi again!
I've tried using your example, terry, but I keep getting this message every time:

Run-Time error '3033':
Du har ikke de nødvendige tilladelser til at bruge objektet "sys". Få systemadministrator eller den person, der oprettede dette objekt, til at give dig de nødvendige tilladelser.

And it doesn't matter which account I'm using to perform the "Change Password" operation! Been searching the net for a solution to the 3033 error code, without luck.....
Avatar billede terry Ekspert
28. oktober 2002 - 08:51 #18
Well I dont know what to suggest! If you are using Access security then this should work!

You obvioulsy need to change OldPassword and NewPassword with the correct passwords.

When Access starts are you getting a small dialog where you have to enter the user and password?
Avatar billede dougheffernan Nybegynder
28. oktober 2002 - 09:03 #19
yes
Avatar billede dougheffernan Nybegynder
28. oktober 2002 - 09:05 #20
Is it because of my VBA references?
Avatar billede dougheffernan Nybegynder
28. oktober 2002 - 09:07 #21
My VBA references are:
Visual Basic for Applications
Microsoft Access 9.0 Object Library
OLE Automation
Microsoft ActiveX Data Objects 2.1 Library
Microsoft DAO 3.6 Object Library
Avatar billede terry Ekspert
28. oktober 2002 - 09:08 #22
Which version of Access are you using?
Avatar billede dougheffernan Nybegynder
28. oktober 2002 - 09:10 #23
2000
Avatar billede terry Ekspert
28. oktober 2002 - 09:13 #24
I am sure that method I gave should work in 2000 also. I wouldnt have thought that ONLY admin can change users passwords, this is NOT logical.

I will have a look around and IF I find something will get back, otherwise I dont know what to suggest!
Avatar billede dougheffernan Nybegynder
28. oktober 2002 - 09:17 #25
Can you tell me why THIS code works:

Sub ChangePasswords()
  Dim ws As Workspace, usr As User
  Set ws = DBEngine.Workspaces(0)
  ws.Users(CurrentUser).NewPassword "oldpassword", "newpassword"
End Sub

And THIS doesn't:

Sub ChangePasswords()
  Dim ws As Workspace, usr As User
  Set ws = DBEngine.Workspaces(0)
  OldPassword = Tekst2.Value
  NewPassword = InputBox("You Must Enter a Password Before Proceeding", "Enter Password")
  ws.Users(CurrentUser).NewPassword "OldPassword", "NewPassword"
End Sub
Avatar billede dougheffernan Nybegynder
28. oktober 2002 - 09:21 #26
This is the code that works, but from what you're saying, I can't change the password of a user without "entering" the users current password, right? So, how do I retrieve that password?

Public Function test()
  Dim ws As Workspace, usr As User
  Set ws = DBEngine.Workspaces(0)
  NewPassword = Tekst2.Value
  ws.Users(CurrentUser).NewPassword "OldPassword", NewPassword
End Function
Avatar billede terry Ekspert
28. oktober 2002 - 09:28 #27
To change a password will need THREE pieces of data.

User Name
The current password (OldPassWord)
The new password (NewPassWord)

So IF you change your code to THIS then it SHOULD work

Sub ChangePasswords()
  Dim ws As Workspace, usr As User
  Set ws = DBEngine.Workspaces(0)
  OldPassword = Tekst2.Value
  NewPassword = InputBox("You Must Enter a Password Before Proceeding", "Enter Password")
  ws.Users(CurrentUser).NewPassword OldPassword, NewPassword
End Sub
Avatar billede dougheffernan Nybegynder
28. oktober 2002 - 09:32 #28
Yes, and it does, but I'd like for the currentuser to enter ONLY the new password, isn't there a way to retrieve his/her password using VBA?

I've tried with this code, but get an error: "invalid use of property", in this line:  OldPassword = ws.Users(CurrentUser).Password


  Dim ws As Workspace, usr As User
  Set ws = DBEngine.Workspaces(0)
  NewPassword = Tekst2.Value
  OldPassword = ws.Users(CurrentUser).Password
  ws.Users(CurrentUser).NewPassword OldPassword, NewPassword
Avatar billede terry Ekspert
28. oktober 2002 - 09:36 #29
Thisi wasnt the original question?
I will see what I can do!
Avatar billede dougheffernan Nybegynder
28. oktober 2002 - 09:38 #30
I know, also raised the points to "compensate".....
Avatar billede dougheffernan Nybegynder
28. oktober 2002 - 09:38 #31
;)
Avatar billede terry Ekspert
28. oktober 2002 - 09:43 #32
am am looking
Avatar billede terry Ekspert
28. oktober 2002 - 10:50 #33
Hi again!

I dont think I am going to be able to help you in finding the password of the current user!
I have looked around and dont seem to be able to find anything which will give me this information!

It is quite normal to get the user to enter the OLD and NEW passwords when changing passwords. This makes sure that it is actually the correct user and not someone who gets access to the application for a short period of time. I am sure you cab see the implications with this.
Avatar billede dougheffernan Nybegynder
28. oktober 2002 - 11:05 #34
I've also searched the entire net(!) for info on how to retrieve a users password using VBA, don't think it can be done.....the points are yours, thanks for helping.
Avatar billede dougheffernan Nybegynder
28. oktober 2002 - 11:07 #35
Yes, I can see the implications...........the only problem is, that if the user doesn't enter his/her old password, I can't change the password....and if they enter the "wrong" old password, I get an error, but I guess I can suppress it and just show them a dialog that says something like: "an error has occured, please check your passwords and try again"
Avatar billede terry Ekspert
28. oktober 2002 - 11:16 #36
you can check which error number you get using the following when you enter the wrong password

err.number

then once you have this number you have can ctach this error and display a message saying they have entered the wrong password.

Thanks :o)
Avatar billede dougheffernan Nybegynder
28. oktober 2002 - 11:59 #37
Well, if I use err.number, I get '3033'! :(
(which doesn't necessarily mean that the user has entered the wrong password, but ........what the heck...)
Avatar billede terry Ekspert
28. oktober 2002 - 12:13 #38
if you try to change the password using the WRONG password then the number youget SHOULD be because you used the wrong password

The message is something like
"You don't have the necessary permissions to use the 'UserName' object.  Have your system administrator or the person who created this object establish the appropriate permissions for you."
Avatar billede dougheffernan Nybegynder
28. oktober 2002 - 12:15 #39
Yes, that's the one, terry. Thank you soooo much.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester