Skip to content

Commit ef89c31

Browse files
Recovery Mode: Use PasswordHash API directly when validating keys.
Previously, the wp_check_password function was used for validating keys, while the PasswordHash class was used for creating keys. This would prevent Recovery Mode from working on sites that provide a custom implementation for the wp_check_password pluggable function. Props calvinalkan. Fixes #56787. git-svn-id: https://develop.svn.wordpress.org/trunk@55397 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 683bba1 commit ef89c31

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/wp-includes/class-wp-recovery-mode-key-service.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,15 @@ public function generate_and_store_recovery_mode_key( $token ) {
8585
*
8686
* @since 5.2.0
8787
*
88+
* @global PasswordHash $wp_hasher
89+
*
8890
* @param string $token The token used when generating the given key.
8991
* @param string $key The unhashed key.
9092
* @param int $ttl Time in seconds for the key to be valid for.
9193
* @return true|WP_Error True on success, error object on failure.
9294
*/
9395
public function validate_recovery_mode_key( $token, $key, $ttl ) {
96+
global $wp_hasher;
9497

9598
$records = $this->get_keys();
9699

@@ -106,7 +109,12 @@ public function validate_recovery_mode_key( $token, $key, $ttl ) {
106109
return new WP_Error( 'invalid_recovery_key_format', __( 'Invalid recovery key format.' ) );
107110
}
108111

109-
if ( ! wp_check_password( $key, $record['hashed_key'] ) ) {
112+
if ( empty( $wp_hasher ) ) {
113+
require_once ABSPATH . WPINC . '/class-phpass.php';
114+
$wp_hasher = new PasswordHash( 8, true );
115+
}
116+
117+
if ( ! $wp_hasher->CheckPassword( $key, $record['hashed_key'] ) ) {
110118
return new WP_Error( 'hash_mismatch', __( 'Invalid recovery key.' ) );
111119
}
112120

0 commit comments

Comments
 (0)