Make WordPress Core

Ticket #45845: 45845.3.diff

File 45845.3.diff, 3.1 KB (added by spacedmonkey, 7 years ago)
  • src/wp-includes/user.php

     
    23172317                return new WP_Error( 'invalid_key', __( 'Invalid key.' ) );
    23182318        }
    23192319
    2320         $row = $wpdb->get_row( $wpdb->prepare( "SELECT ID, user_activation_key FROM $wpdb->users WHERE user_login = %s", $login ) );
    2321         if ( ! $row ) {
     2320        $user = get_user_by( 'login', $login );
     2321        if ( ! $user ) {
    23222322                return new WP_Error( 'invalid_key', __( 'Invalid key.' ) );
    23232323        }
    23242324
     
    23362336         */
    23372337        $expiration_duration = apply_filters( 'password_reset_expiration', DAY_IN_SECONDS );
    23382338
    2339         if ( false !== strpos( $row->user_activation_key, ':' ) ) {
    2340                 list( $pass_request_time, $pass_key ) = explode( ':', $row->user_activation_key, 2 );
     2339        if ( false !== strpos( $user->user_activation_key, ':' ) ) {
     2340                list( $pass_request_time, $pass_key ) = explode( ':', $user->user_activation_key, 2 );
    23412341                $expiration_time                      = $pass_request_time + $expiration_duration;
    23422342        } else {
    2343                 $pass_key        = $row->user_activation_key;
     2343                $pass_key        = $user->user_activation_key;
    23442344                $expiration_time = false;
    23452345        }
    23462346
     
    23512351        $hash_is_correct = $wp_hasher->CheckPassword( $key, $pass_key );
    23522352
    23532353        if ( $hash_is_correct && $expiration_time && time() < $expiration_time ) {
    2354                 return get_userdata( $row->ID );
     2354                return get_userdata( $user->ID );
    23552355        } elseif ( $hash_is_correct && $expiration_time ) {
    23562356                // Key has an expiration time that's passed
    23572357                return new WP_Error( 'expired_key', __( 'Invalid key.' ) );
    23582358        }
    23592359
    2360         if ( hash_equals( $row->user_activation_key, $key ) || ( $hash_is_correct && ! $expiration_time ) ) {
     2360        if ( hash_equals( $user->user_activation_key, $key ) || ( $hash_is_correct && ! $expiration_time ) ) {
    23612361                $return  = new WP_Error( 'expired_key', __( 'Invalid key.' ) );
    2362                 $user_id = $row->ID;
     2362                $user_id = $user->ID;
    23632363
    23642364                /**
    23652365                 * Filters the return value of check_password_reset_key() when an
  • tests/phpunit/tests/auth.php

     
    242242                                'ID' => $this->user->ID,
    243243                        )
    244244                );
     245                clean_user_cache( $this->user );
    245246
    246247                // A valid key should be accepted
    247248                $check = check_password_reset_key( $key, $this->user->user_login );
     
    279280                                'ID' => $this->user->ID,
    280281                        )
    281282                );
     283                clean_user_cache( $this->user );
    282284
    283285                // An expired but otherwise valid key should be rejected
    284286                $check = check_password_reset_key( $key, $this->user->user_login );
     
    316318                                'ID' => $this->user->ID,
    317319                        )
    318320                );
     321                clean_user_cache( $this->user );
    319322
    320323                // A legacy user_activation_key should not be accepted
    321324                $check = check_password_reset_key( $key, $this->user->user_login );
     
    345348                                'ID' => $this->user->ID,
    346349                        )
    347350                );
     351                clean_user_cache( $this->user );
    348352
    349353                // A plaintext user_activation_key should not allow an otherwise valid key to be accepted
    350354                $check = check_password_reset_key( $key, $this->user->user_login );