Results 1 to 2 of 2
2004-02-09, 13:56 #1
- Join Date
- Oct 2001
- Newport, Gwent, Wales
- Thanked 0 Times in 0 Posts
Changing User Passwords (Access 2K)
OK, I've just 'rolled out' a database, for the first time I've used the Access Security wizard to secure the system, well the obvious has happened. One of the users has forgotten what password they created (I foolishly didn't get them to tell me). Now I've cleared the password so they can log on without entering anything into the password box, but as I'm sure this will happen again how do I allow them to create a new password through a form? Otherwise I have to go to them and sort it out via the Tools menu, this is restricted to any other user.
I've read the Access Security FAQ and it suggests some code similar to what is shown below, but when this code runs it errors out with a message about not having permissions. So, what do I need to do to temporarily assign the necessary permissions to my users?
Dim strUser As String
Dim strPassword As String
Dim WrkSpce As Workspace
Dim Usr As User
strUser = CurrentUser
Set WrkSpce = DBEngine.Workspaces(0)
Set Usr = WrkSpce.Users(strUser)
If IsNull(Me.PwEntryTxt) Then
MsgBox "no password to change to"
If Me.PwEntryTxt = Me.PwConfirmTxt Then
strPassword = Me.PwEntryTxt
Usr.NewPassword " ", strPassword
MsgBox strUser & strPassword
MsgBox "Nope, code still aint working"
This is still very much 'alpha' code so that's why it's offering me the password and user name in a message box, I want some confidence that this is working right [img]/forums/images/smilies/wink.gif[/img] The PWEntryTxt and PWConfirmTxt references are text boxes on the form I intend to aloow the users access to to change their passwords. Eventually they'll be able to change them periodically, but for now it's just a case of entering a new password once the old one is cleared by myself or the person who will be administrating it.
2004-02-09, 23:16 #2
- Join Date
- Jun 2002
- Mt Macedon, Victoria, Australia
- Thanked 45 Times in 44 Posts
Re: Changing User Passwords (Access 2K)
Here is the code I use to do this job.
My form has three text boxes, one for the current password, and two for the new.
I don't get errors about permissions, so I don't do anything to set them.
I have just tested it again logging in as an ordinary user with no admin permissions and it still works OK.
I should add some extra code to check the the new password is no longer than 14 characters.
<pre>Private Sub CmdChangePwd_Click()
On Error GoTo Err_CmdChangePwd_Click
Dim W As Workspace, U As user
Dim strUserName As String
Dim strcurrentPassword As String
Dim strNewPassword As String
Set W = DBEngine.Workspaces(0)
strUserName = CurrentUser()
Set U = W.Users(strUserName)
If IsNull(Me![txtpassword]) Then
strcurrentPassword = ""
strcurrentPassword = Me![txtpassword]
If (Me!txtNewPassword1 = Me!txtnewPassword2) Then
strNewPassword = Me!txtNewPassword1
U.NewPassword strcurrentPassword, strNewPassword
MsgBox ("Your password has been changed")
DoCmd.Close acForm, Me.Name
MsgBox ("The two new passwords you entered were not the same. Please try again")
Me!txtNewPassword1 = ""
Me!txtnewPassword2 = ""
If Err.Number = 3033 Then
MsgBox ("You entered the wrong password")