Changing current user password (1 Viewer)

Dave_cha

Registered User.
Local time
Today, 14:59
Joined
Nov 11, 2002
Messages
119
I'm trying to write a module within Access 97 which will prompt the user to confirm their existing password and enter a new password. The 'Change Logon Password' option under Users and Group Accounts' provides this facility though I'm trying to build a user friendly button within a form. Users accessing my database won't have access to the tools menu.
Users currently authenticate through a central system.mdw.

I'd be very grateful If anyone out there could fwd. me a previously written module which performs this function or point me in the right direction.
 
Last edited:

Autoeng

Why me?
Local time
Today, 09:59
Joined
Aug 13, 2002
Messages
1,302
I've got this in my app but there are so many other things tired up within it it will take me a while to give you a clean version. In the meantime check www.rogersaccesslibrary.com as he may have an example.

Autoeng
 

Autoeng

Why me?
Local time
Today, 09:59
Joined
Aug 13, 2002
Messages
1,302
Here is the code I am using. I hope that it doesn't contain any loose ends. Create a "Change Password" form with "Current Password", "New Password" and "Confirm New Password" unbound text boxes. Create command buttons for "OK" and "Cancel". Look through the code for call outs that you will have to change. I set these in general to "yourform" or "yourfield".

For the "OK" button use the code below for the On Click Event.

Code:
Private Sub OK_Click()
On Error GoTo Err_OK_Click

    Dim strUser As String
    Dim strOldPW1 As String
    Dim strNewPW1 As String
    Dim strNewPW2 As String
    Dim strMsg As String
    Dim strTitle As String
    Dim intType As Integer
    Dim wrk As Object
    Dim usrLocal As Object

    strUser = CurrentUser()
    If strUser = "Admin" Then
        strMsg = "Password for Admin can't be changed. Please contact system administrator."
        strTitle = "Password"
        intType = 16
        MsgBox strMsg, intType, strTitle
        Exit Sub
    End If
    
    If IsNull(Forms![yourform]![youroldpasswordfield]) Then
    '    strMsg = "No Old Password entered"
    '    strTitle = "Password"
    '    intType = 16
    '    MsgBox strMsg, intType, strTitle
    '    Exit Sub
        strOldPW1 = ""
    Else
        strOldPW1 = Forms![yourfrom]![youroldpasswordfield]
    End If

    If IsNull(Forms![yourfrom]![yournewpasswordfield]) Then
        strMsg = "No New Password entered"
        strTitle = "Password"
        intType = 16
        MsgBox strMsg, intType, strTitle
        Exit Sub
    End If

    If IsNull(Forms![yourform]![yournewpasswordconfirmfield]) Then
        strMsg = "No verify entered"
        strTitle = "Password"
        intType = 16
        MsgBox strMsg, intType, strTitle
        Exit Sub
    End If

    strNewPW1 = Forms![yourfrom]![yournewpasswordfield]
    strNewPW2 = Forms![yourfrom]![yournewpasswordfieldconfirm]
    Set wrk = DBEngine.Workspaces(0)
    Set usrLocal = wrk.Users(strUser)
    
    '* Check if New password and verify are the same
    If strNewPW1 = strNewPW2 Then
        '* Check Length of new password
        If Len(strNewPW1) <= 14 Then
            usrLocal.NewPassword strOldPW1, strNewPW1
        Else
            strMsg = "Password can have a length of maximum 14 characters."
            strTitle = "Password"
            intType = 16
            MsgBox strMsg, intType, strTitle
            Exit Sub
        End If
    Else
        strMsg = "Please verify the new password by entering it in the"
        strMsg = strMsg + Chr$(13) & Chr$(10)
        strMsg = strMsg + "verify box."
        strTitle = "Password"
        intType = 16
        MsgBox strMsg, intType, strTitle
        Exit Sub
    End If

    DoCmd.Close

Exit_OK_Click:
    Exit Sub

Err_OK_Click:
    If Err = 3033 Then
        strMsg = "Old Password not correct for this user profile."
        strTitle = "Password"
        intType = 16
        MsgBox strMsg, intType, strTitle
        Exit Sub
    Else
        MsgBox Error$
        
        Resume Exit_OK_Click
    End If

End Sub

You can also place a text box to display the current users name on the form if you like. Set the text box control source to =CurrentUser()

Autoeng
 

danikuper

Registered User.
Local time
Today, 09:59
Joined
Feb 6, 2003
Messages
147
That is exactly what I was looking for.

Great code!
Thanks for sharing !!!

:)
 

Autoeng

Why me?
Local time
Today, 09:59
Joined
Aug 13, 2002
Messages
1,302
I recently posted a link to this post for another user and noticed that David had said
Users currently authenticate through a central system.mdw.

Oh, that is so bad. Never use the System.mdw workgroup to secure your databases. It is like using no security at all as everyone has system.mdw on their computer. If the user decides not to use the shortcut to access the db they won't have any problem opening it.

Autoeng
 

hooi

Registered User.
Local time
Today, 21:59
Joined
Jul 22, 2003
Messages
158
Hi Autoeng,

Please ignore my earlier reply in another thread regarding the change of user password. I've used your code here in this thread. Thank you. It works great, just what I wanted.
 

Users who are viewing this thread

Top Bottom