User.change_password - Python API

Changes a user’s password. Regular users may only change their own passwords and super-users may change any other person’s password. No matter who is changing the password, the new one must confirm to the configuration.

Super-users may also set password expiry and a flag indicating that the referenced user change his or her password the next time this person logs in.

API

self.sso.user.change_password

change_password(self, cid, current_ust, current_app, remote_addr)

Changes a user’s password. Either current user’s, as identified by current_ust or another person’s, if user_id is in the ‘data’ dictionary.

Parameters:
  • cid (string) – Correlation ID used by audit log
  • data (dict) –

    A dictionary of input values to change the password with

    Name Datatype Optional Needs super-user Notes
    old_password string Yes Required if current user changes his or her own password
    new_password string New password to set for user
    user_id string Yes Yes ID of user whose password is to be changed, required if a super-user wants to change another person’s password
    password_expiry integer Yes Yes Optionally, after how many days from current time the password will expire. If not set, a default value from configuration will be used.
    must_change bool Yes Yes If True, the person whose password is being change will need to reset it on next login
  • current_ust (string) – Current user’s UST
  • current_app (string) – Name of application the current user is issuing the call from
  • remote_addr (string) – User’s remote address
Return type:

(None)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, print_function, unicode_literals

# Zato
from zato.server.service import Service

class ChangePasswordCurrentUser(Service):

    def handle(self):

        # Data obtained from request and/or WSGI environment
        ust = 'gAAAAABalFycY50Budi...'
        current_app = 'CRM'
        remote_addr = '127.0.0.1'

        # Since this is a password change for current user,
        # both old and new password are needed on input
        data = {
            'old_password': 'mCryhVlCePjuyCkV1blieB2gJIIZNiO3',
            'new_password': 'Q9mr70M8hKshqbCK6uLArAFVCdqcTdEh',
        }

        # Change the password now, no exception = success
        self.sso.user.change_password(self.cid, data, current_ust, current_app, remote_addr)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, print_function, unicode_literals

# Zato
from zato.server.service import Service

class ChangePasswordAnotherUser(Service):

    def handle(self):

        # Data obtained from request and/or WSGI environment
        ust = 'gAAAAABalFycY50Budi...'
        current_app = 'CRM'
        remote_addr = '127.0.0.1'

        # This time around, a super-user changes another person's password
        # so the old password is not needed. On top of it, the other user
        # will need to change the password the next time he or she logs in.
        data = {
            'user_id':      'zusr6pxpqqg4j09t5vhw1ehtmebshy',
            'new_password': '5c5Apw67534s55ukRkEZSVyH3DKr2ajN',
            'must_change':   True,
        }

        # Change the password now, no exception = success
        self.sso.user.change_password(self.cid, data, current_ust, current_app, remote_addr)