0

I have a system in which I create users by Email ID when they make a purchase.

I want to send them the link to send Password when they click on link so the option is I initiate the password reset procedure in the code and I can make a URL to initiate the procedure, so the user will receive the URL with

http://myurl.com/my-account/lost-password/?key=U7EJyOI2o84ylp99DuoU&login=user@xyz.com

I tried to generate password reset key by this:

get_password_reset_key('user@xyz.com');

but when I append that key in URL, wordpress says Invalid key

I think I'm missing something here in my code flow that is probably associating that key to the user so when user clicks that key key must look valid to wordpress.

In short I want to clear the phase where wordpress generates reset key for user and that key must be valid when I check it by URL so password reset can be done.

Please help me here.

1

According to the WordPress Code Reference you have to pass the user object to get_password_reset_key() instead of the mail address. Maybe a solution for your problem will be:

$user = get_user_by( 'email', 'user@xyz.com' );
$reset_key = get_password_reset_key( $user );
  • I refered it before this question. It didn't work. It just generates a key but Key doesn't get stored in encrypted form. So it says invalid key. – Hardik Trivedi Apr 18 '17 at 13:21
  • You set the url parameter "login" to the email. It should be set to the login name of the user. – ahendwh2 Apr 18 '17 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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