Admin: reset another user’s password#
Estimated reading time: 2’
Resetting another user’s password as an admin is pretty straight-forward. You simply need to generate a password-reset token for a specific user and send it to them in a secure way.
Don’t worry, once the token is used it becomes invalid, exposing it afterwards poses no security risks.
1. Login using your credentials#
First, login to the Datasite using your admin credentials:
admin_client = sy.login(
url=SERVER_URL,
port=SERVER_PORT,
email=ADMIN_EMAIL,
password=ADMIN_PASSWORD,
)
2. Select the user to reset their password#
Search the users and select the one that needs their password reset. The easiest way to do this is by email.
Note
The .users.search
function returns a list, so you also need to select an element from that list (typically the first one, if you search by using the complete email address).
user = admin_client.users.search(email=USER_EMAIL)[0]
3. Generate a password-reset token#
token = admin_client.users.request_password_reset(user.id)
print(token)
4. Send the token#
After generating the token, send it to the user in a secure way.
They will use it to reset their password using a guest client, like below:
guest_client = sy.login_as_guest(
url=SERVER_URL,
port=SERVER_PORT,
)
guest_client.reset_password(
token=token,
new_password='*****'
)
After reseting their password, they will be able to login as usual using the new one.
All done!