@@ -1811,6 +1811,47 @@ def get_users(token, customer_id = 0):
18111811
18121812 return (jobj ["users" ], "" )
18131813
1814+ @staticmethod
1815+ def change_password (token , username , new_password , old_password = "" , password_reset_token = "" , admin_mode = False ):
1816+
1817+ """
1818+ This method will change the password of a user. It supports 3 modes of
1819+ operation. With an access token that has UserAuthNormal permission
1820+ (i.e. without admin permission), the password can either be changed by
1821+ providing the old password or a password reset token, which can be
1822+ generated using Reset Password Token method. Finally, if you call this
1823+ method with an access token that has UserAuthAdmin permission, it will
1824+ allow you to set AdminMode to True and only provide the NewPassword.
1825+
1826+ More docs: https://app.cryptolens.io/docs/api/v3/ChangePassword
1827+ """
1828+
1829+ try :
1830+ response = HelperMethods .send_request ("/userauth/ChangePassword/" ,\
1831+ {"token" :token ,\
1832+ "username" :username ,\
1833+ "OldPassword" : old_password ,\
1834+ "NewPassword" :new_password ,\
1835+ "PasswordResetToken" : password_reset_token ,\
1836+ "AdminMode" :admin_mode })
1837+ except HTTPError as e :
1838+ response = e .read ()
1839+ except URLError as e :
1840+ return (None , "Could not contact the server. Error message: " + str (e ))
1841+ except Exception :
1842+ return (None , "Could not contact the server." )
1843+
1844+ jobj = json .loads (response )
1845+
1846+ if jobj == None or not ("result" in jobj ) or jobj ["result" ] == 1 :
1847+ if jobj != None :
1848+ return (None , jobj ["message" ])
1849+ else :
1850+ return (None , "Could not contact the server." )
1851+
1852+ return (jobj , "" )
1853+
1854+
18141855 @staticmethod
18151856 def reset_password_token (token , username ):
18161857
0 commit comments