2

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.

1 Answer 1

5

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.

4
  • hey man, I did everything but edit_user_profile_update doesnt run, the user_register run perfectly
    – zEn feeLo
    Commented Mar 29, 2019 at 0:27
  • I also tested profile_update and user_profile_update what can be the problem I asked my question here too
    – zEn feeLo
    Commented Mar 29, 2019 at 0:28
  • stackoverflow.com/questions/55400887/…
    – zEn feeLo
    Commented Mar 29, 2019 at 0:28
  • the second hook is wrong, didnt work for me, it should be profile_update
    – zEn feeLo
    Commented Mar 29, 2019 at 2:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.