25. oktober 2002 - 10:52Der 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?
I dette særtema ser vi på, hvordan cloud og AI bliver fundamentet for virksomhedernes digitale forretning, og hvordan de nye muligheder for automatisering og forretningsværdi kan udnyttes uden at miste overblik, sikkerhed og menneskelig kontrol.
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
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.
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
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
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.....
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
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
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
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
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
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.
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.
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"
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...)
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."
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.