Forum Discussion
REST API example change password
I need to change the password for admin and root accounts on our big-ip servers. I found this api end point but need more info on the parameters or a working example.
https://clouddocs.f5.com/api/icontrol-rest/APIRef_tm_auth_password.html
- jaikumar_f5
Noctilucent
Something like below should do the trick,
curl -sk -u useraccount -H "Content-Type: application/json" -X PATCH https://hostname/mgmt/tm/auth/user/useraccount -d '{ "password": "newpassword" }'
Once above is it will prompt for existing password and the change will reflect. The user will have the newpassword set as password.
If you'd need you can send the existing password in the query too.
curl -sk -u useraccount:oldpassword -H "Content-Type: application/json" -X PATCH https://hostname/mgmt/tm/auth/user/useraccount -d '{ "password": "newpassword" }'
Hope this helps.
- Shahid_Khan
Nimbostratus
Pre-requisite:
1- Admin role user which has authority to change the password
2- user's username of which password will change
3- New password of the user's username
User: test
Admin User: f5osadmin
Python: working on 2.7 and 3
import requests from requests.auth import HTTPBasicAuth import json import urllib3 urllib3.disable_warnings() urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) # suppress SSL error def change_password(b, url, creds): payload = { } payload['password'] = creds[0] #print("Payload: ", payload) response1 = b.patch(url, data=json.dumps(payload)) #print(response1.content) #print(response1.status_code) #print(response1.request.body) # Return Boolean if response1 .status_code == int(200): pass_bool= True return pass_bool elif response1 .status_code == int(400) or response1 .status_code == int(401) : pass_bool= False return pass_bool ###### TO CHANGE Other non admin user PASSWORD ################## creds=["MyNewPassword123!"] # user "test" new password b = requests.session() b.auth = ('f5osadmin', 'f5OsaDm1n!') # F5 admin role user credentials. b.verify = False b.headers.update({'Content-Type':'application/json'}) if change_password(b, 'https://f5.sik.domain.com/mgmt/tm/auth/user/test', creds): # user test print("password change successful") else: print("password change failed") ###### END TO CHANGE PASSWORD ##################
Above is basic python code with few verification in print and which can be enhance with try exception
Hope this will help
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com