How to get the password and username of the add new user form (admin back end) in wordpress

The question:

I am trying to get the username and password that entered by the wordpress admin in the add new user screen to use those into creating a webmail account using cpanel api.

How to do that? is there is any hook for it?

Also, When the user id changing his password, I want to get the new and old password and use it to change the one for the webmail account.

  • I am not looking for the cpanel part, just the wordpress part.

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

You’ll need three hooks:

1: user_register

This is for when the user is created via the admin back-end. The username will be available via $_POST['user_login'] and the password will be available via $_POST['pass1'].

2: edit_user_profile_update

This is for when the password is updated on the profile page by the user or admin. The username will be available via $_POST['user_login'] and the password will be available via $_POST['pass1'].

3: password_reset

This is for when the user resets their password using the forgot password page. The username will be available via the first argument $user using $user->user_login. The password will be available via the second argument $new_pass.

In terms of getting the old password, I don’t think you can. The password is hashed and stored in the database. You have access to the hash, but you can’t reconstruct the old password from it.

The only option you have there is to store the password somewhere else in an encrypted way so you can retrieve it later and decrypt it, however this method is not recommended from a security point of view.

I’d recommend finding a way to update the password in cPanel without having the old password.

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment