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.

self.sso.user.change_password

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

  • cid: Correlation ID used by audit log
  • data: A dictionary of input values to change the password with
  • current_ust: Current user's UST
  • current_app: Name of application the current user is issuing the call from
  • remote_addr: User's remote address
  • Returns: (None)

The 'data' dictionary is in the format described below:

NameDatatypeOptionalNeeds super-userNotes
old_passwordstringYes---Required if current user changes his or her own password
new_passwordstring------New password to set for user
user_idstringYesYesID of user whose password is to be changed, required if a super-user wants to change another person's password
password_expiryintegerYesYesOptionally, after how many days from current time the password will expire. If not set, a default value from configuration will be used.
must_changeboolYesYesIf True, the person whose password is being change will need to reset it on next login
# -*- coding: utf-8 -*-

# 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': '<old-password>',
            'new_password': '<new-password>',
        }

        # Change the password now, no exception = success
        self.sso.user.change_password(self.cid, data, current_ust, current_app, remote_addr)
# -*- coding: utf-8 -*-

# 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': '<new-password>',
            'must_change':   True,
        }

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