Make WordPress Core


Ignore:
Timestamp:
10/08/2015 12:10:41 AM (11 years ago)
Author:
SergeyBiryukov
Message:

Reset Password: Move the code for creating password reset key into a new function, get_password_reset_key(), and use it in retrieve_password().

Previously: [25231].

Props DH-Shredder.
Fixes #34180.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-login.php

    r34910 r34923  
    314314        $user_login = $user_data->user_login;
    315315        $user_email = $user_data->user_email;
    316 
    317         /**
    318          * Fires before a new password is retrieved.
    319          *
    320          * @since 1.5.0
    321          * @deprecated 1.5.1 Misspelled. Use 'retrieve_password' hook instead.
    322          *
    323          * @param string $user_login The user login name.
    324          */
    325         do_action( 'retreive_password', $user_login );
    326 
    327         /**
    328          * Fires before a new password is retrieved.
    329          *
    330          * @since 1.5.1
    331          *
    332          * @param string $user_login The user login name.
    333          */
    334         do_action( 'retrieve_password', $user_login );
    335 
    336         /**
    337          * Filter whether to allow a password to be reset.
    338          *
    339          * @since 2.7.0
    340          *
    341          * @param bool true           Whether to allow the password to be reset. Default true.
    342          * @param int  $user_data->ID The ID of the user attempting to reset a password.
    343          */
    344         $allow = apply_filters( 'allow_password_reset', true, $user_data->ID );
    345 
    346         if ( ! $allow ) {
    347                 return new WP_Error( 'no_password_reset', __('Password reset is not allowed for this user') );
    348         } elseif ( is_wp_error( $allow ) ) {
    349                 return $allow;
    350         }
    351 
    352         // Generate something random for a password reset key.
    353         $key = wp_generate_password( 20, false );
    354 
    355         /**
    356          * Fires when a password reset key is generated.
    357          *
    358          * @since 2.5.0
    359          *
    360          * @param string $user_login The username for the user.
    361          * @param string $key        The generated password reset key.
    362          */
    363         do_action( 'retrieve_password_key', $user_login, $key );
    364 
    365         // Now insert the key, hashed, into the DB.
    366         if ( empty( $wp_hasher ) ) {
    367                 require_once ABSPATH . WPINC . '/class-phpass.php';
    368                 $wp_hasher = new PasswordHash( 8, true );
    369         }
    370         $hashed = time() . ':' . $wp_hasher->HashPassword( $key );
    371         $wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => $user_login ) );
     316        $key = get_password_reset_key( $user_data );
     317
     318        if ( is_wp_error( $key ) ) {
     319                return $key;
     320        }
    372321
    373322        $message = __('Someone requested that the password be reset for the following account:') . "\r\n\r\n";
Note: See TracChangeset for help on using the changeset viewer.