- Timestamp:
- 02/17/2025 11:22:33 AM (3 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-recovery-mode-key-service.php
r58975 r59828 38 38 * 39 39 * @since 5.2.0 40 * 41 * @global PasswordHash $wp_hasher Portable PHP password hashing framework instance. 40 * @since 6.8.0 The stored key is now hashed using wp_fast_hash() instead of phpass. 42 41 * 43 42 * @param string $token A token generated by {@see generate_recovery_mode_token()}. … … 45 44 */ 46 45 public function generate_and_store_recovery_mode_key( $token ) { 47 48 global $wp_hasher;49 50 46 $key = wp_generate_password( 22, false ); 51 52 if ( empty( $wp_hasher ) ) {53 require_once ABSPATH . WPINC . '/class-phpass.php';54 $wp_hasher = new PasswordHash( 8, true );55 }56 57 $hashed = $wp_hasher->HashPassword( $key );58 47 59 48 $records = $this->get_keys(); 60 49 61 50 $records[ $token ] = array( 62 'hashed_key' => $hashed,51 'hashed_key' => wp_fast_hash( $key ), 63 52 'created_at' => time(), 64 53 ); … … 86 75 * @since 5.2.0 87 76 * 88 * @global PasswordHash $wp_hasher Portable PHP password hashing framework instance.89 *90 77 * @param string $token The token used when generating the given key. 91 * @param string $key The unhashedkey.78 * @param string $key The plain text key. 92 79 * @param int $ttl Time in seconds for the key to be valid for. 93 80 * @return true|WP_Error True on success, error object on failure. 94 81 */ 95 82 public function validate_recovery_mode_key( $token, $key, $ttl ) { 96 global $wp_hasher;97 98 83 $records = $this->get_keys(); 99 84 … … 110 95 } 111 96 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'] ) ) { 97 if ( ! wp_verify_fast_hash( $key, $record['hashed_key'] ) ) { 118 98 return new WP_Error( 'hash_mismatch', __( 'Invalid recovery key.' ) ); 119 99 } … … 170 150 * 171 151 * @since 5.2.0 152 * @since 6.8.0 Each key is now hashed using wp_fast_hash() instead of phpass. 153 * Existing keys may still be hashed using phpass. 172 154 * 173 * @return array Associative array of $token => $data pairs, where $data has keys 'hashed_key' 174 * and 'created_at'. 155 * @return array { 156 * Associative array of token => data pairs, where the data is an associative 157 * array of information about the key. 158 * 159 * @type array ...$0 { 160 * Information about the key. 161 * 162 * @type string $hashed_key The hashed value of the key. 163 * @type int $created_at The timestamp when the key was created. 164 * } 165 * } 175 166 */ 176 167 private function get_keys() { … … 182 173 * 183 174 * @since 5.2.0 175 * @since 6.8.0 Each key should now be hashed using wp_fast_hash() instead of phpass. 184 176 * 185 * @param array $keys Associative array of $token => $data pairs, where $data has keys 'hashed_key' 186 * and 'created_at'. 177 * @param array $keys { 178 * Associative array of token => data pairs, where the data is an associative 179 * array of information about the key. 180 * 181 * @type array ...$0 { 182 * Information about the key. 183 * 184 * @type string $hashed_key The hashed value of the key. 185 * @type int $created_at The timestamp when the key was created. 186 * } 187 * } 187 188 * @return bool True on success, false on failure. 188 189 */
Note: See TracChangeset
for help on using the changeset viewer.