• Changing User Passwords (Access 2K)

    Author
    Topic
    #400441

    Hello

    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”
    Else
    If Me.PwEntryTxt = Me.PwConfirmTxt Then
    strPassword = Me.PwEntryTxt
    Usr.NewPassword ” “, strPassword
    MsgBox strUser & strPassword
    Else
    MsgBox “Nope, code still aint working”
    End If
    End If

    ExitSub:
    Exit Sub

    ErrHandler:
    MsgBox Err.Description
    Resume ExitSub

    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 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.

    Thanks

    Ian

    Viewing 1 reply thread
    Author
    Replies
    • #781567

      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.

      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 = ""
         Else
            strcurrentPassword = Me![txtpassword]
         End If
          If (Me!txtNewPassword1 = Me!txtnewPassword2) Then
            strNewPassword = Me!txtNewPassword1
            U.NewPassword strcurrentPassword, strNewPassword
            MsgBox ("Your password has been changed")
            DoCmd.Close acForm, Me.Name
          Else
            MsgBox ("The two new passwords you entered were not the same. Please try again")
            Me!txtNewPassword1 = ""
            Me!txtnewPassword2 = ""
            Me!txtNewPassword1.SetFocus
          End If
        
      Exit_CmdChangePwd_Click:
          Exit Sub
      Err_CmdChangePwd_Click:
          If Err.Number = 3033 Then
              MsgBox ("You entered the wrong password")
          Else
              MsgBox Err.Description
           End If
          Resume Exit_CmdChangePwd_Click
      End Sub
      
    • #781568

      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.

      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 = ""
         Else
            strcurrentPassword = Me![txtpassword]
         End If
          If (Me!txtNewPassword1 = Me!txtnewPassword2) Then
            strNewPassword = Me!txtNewPassword1
            U.NewPassword strcurrentPassword, strNewPassword
            MsgBox ("Your password has been changed")
            DoCmd.Close acForm, Me.Name
          Else
            MsgBox ("The two new passwords you entered were not the same. Please try again")
            Me!txtNewPassword1 = ""
            Me!txtnewPassword2 = ""
            Me!txtNewPassword1.SetFocus
          End If
        
      Exit_CmdChangePwd_Click:
          Exit Sub
      Err_CmdChangePwd_Click:
          If Err.Number = 3033 Then
              MsgBox ("You entered the wrong password")
          Else
              MsgBox Err.Description
           End If
          Resume Exit_CmdChangePwd_Click
      End Sub
      
    Viewing 1 reply thread
    Reply To: Changing User Passwords (Access 2K)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: