• Resolved paulchoix

    (@paulchoix)


    I have a function that creates a WordPress user and then sends the user an email greeting with a link to reset their password. However, the key generated by get_password_reset_key never seems to work.

    Here is my code:

    $key = get_password_reset_key( get_user_by( 'id', $user_id ) );
    $password_link = esc_url_raw( add_query_arg( array(
        'action' => 'rp',
        'key' => $key,
        'email' => $user_email
        ), site_url( 'wp-login.php' ) ) );
    $message = 'Welcome, here is a link to reset your password: %s';
    $message = sprintf( $message, $password_link );

    The password link contains a hashed key as expected, but WordPress indicates the key is invalid. I have tried this on both my local development server and with my production setup. I have no idea what I could possibly be getting wrong. Any ideas?

    • This topic was modified 2 years, 6 months ago by paulchoix.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Please do not mind me blind guessing here.

    By any chance is your site hosted on WordPress.com or connected via Jetpack? Or anything else like a custom login plugin that would use a different user table?

    Moderator bcworkz

    (@bcworkz)

    Instead of sending the “email” value, send the “login” value. You want a link similar to:
    https://example.com/wp-login.php?action=rp&key=7weGay9sVj27BXOSauGW&login=foo

    Thread Starter paulchoix

    (@paulchoix)

    That did the trick, thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘WordPress reset password key doesn’t work’ is closed to new replies.