Ticket #45845: 45845.3.diff
| File 45845.3.diff, 3.1 KB (added by , 7 years ago) |
|---|
-
src/wp-includes/user.php
2317 2317 return new WP_Error( 'invalid_key', __( 'Invalid key.' ) ); 2318 2318 } 2319 2319 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 ) { 2322 2322 return new WP_Error( 'invalid_key', __( 'Invalid key.' ) ); 2323 2323 } 2324 2324 … … 2336 2336 */ 2337 2337 $expiration_duration = apply_filters( 'password_reset_expiration', DAY_IN_SECONDS ); 2338 2338 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 ); 2341 2341 $expiration_time = $pass_request_time + $expiration_duration; 2342 2342 } else { 2343 $pass_key = $ row->user_activation_key;2343 $pass_key = $user->user_activation_key; 2344 2344 $expiration_time = false; 2345 2345 } 2346 2346 … … 2351 2351 $hash_is_correct = $wp_hasher->CheckPassword( $key, $pass_key ); 2352 2352 2353 2353 if ( $hash_is_correct && $expiration_time && time() < $expiration_time ) { 2354 return get_userdata( $ row->ID );2354 return get_userdata( $user->ID ); 2355 2355 } elseif ( $hash_is_correct && $expiration_time ) { 2356 2356 // Key has an expiration time that's passed 2357 2357 return new WP_Error( 'expired_key', __( 'Invalid key.' ) ); 2358 2358 } 2359 2359 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 ) ) { 2361 2361 $return = new WP_Error( 'expired_key', __( 'Invalid key.' ) ); 2362 $user_id = $ row->ID;2362 $user_id = $user->ID; 2363 2363 2364 2364 /** 2365 2365 * Filters the return value of check_password_reset_key() when an -
tests/phpunit/tests/auth.php
242 242 'ID' => $this->user->ID, 243 243 ) 244 244 ); 245 clean_user_cache( $this->user ); 245 246 246 247 // A valid key should be accepted 247 248 $check = check_password_reset_key( $key, $this->user->user_login ); … … 279 280 'ID' => $this->user->ID, 280 281 ) 281 282 ); 283 clean_user_cache( $this->user ); 282 284 283 285 // An expired but otherwise valid key should be rejected 284 286 $check = check_password_reset_key( $key, $this->user->user_login ); … … 316 318 'ID' => $this->user->ID, 317 319 ) 318 320 ); 321 clean_user_cache( $this->user ); 319 322 320 323 // A legacy user_activation_key should not be accepted 321 324 $check = check_password_reset_key( $key, $this->user->user_login ); … … 345 348 'ID' => $this->user->ID, 346 349 ) 347 350 ); 351 clean_user_cache( $this->user ); 348 352 349 353 // A plaintext user_activation_key should not allow an otherwise valid key to be accepted 350 354 $check = check_password_reset_key( $key, $this->user->user_login );