Changeset 59578
- Timestamp:
- 01/06/2025 03:21:26 PM (2 weeks ago)
- Location:
- trunk
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/pluggable.php
r59459 r59578 2582 2582 if ( ! function_exists( 'wp_hash' ) ) : 2583 2583 /** 2584 * Gets hash of given string. 2584 * Gets the hash of the given string. 2585 * 2586 * The default algorithm is md5 but can be changed to any algorithm supported by 2587 * `hash_hmac()`. Use the `hash_hmac_algos()` function to check the supported 2588 * algorithms. 2585 2589 * 2586 2590 * @since 2.0.3 2591 * @since 6.8.0 The `$algo` parameter was added. 2592 * 2593 * @throws InvalidArgumentException if the hashing algorithm is not supported. 2587 2594 * 2588 2595 * @param string $data Plain text to hash. 2589 2596 * @param string $scheme Authentication scheme (auth, secure_auth, logged_in, nonce). 2597 * @param string $algo Hashing algorithm to use. Default: 'md5'. 2590 2598 * @return string Hash of $data. 2591 2599 */ 2592 function wp_hash( $data, $scheme = 'auth' ) {2600 function wp_hash( $data, $scheme = 'auth', $algo = 'md5' ) { 2593 2601 $salt = wp_salt( $scheme ); 2594 2602 2595 return hash_hmac( 'md5', $data, $salt ); 2603 // Ensure the algorithm is supported by the hash_hmac function. 2604 if ( ! in_array( $algo, hash_hmac_algos(), true ) ) { 2605 throw new InvalidArgumentException( 2606 sprintf( 2607 /** translators: 1: Name of a cryptographic hash algorithm. 2: List of supported algorithms. */ 2608 __( 'Unsupported hashing algorithm: %1$s. Supported algorithms are: %2$s' ), 2609 $algo, 2610 implode( ', ', hash_hmac_algos() ) 2611 ) 2612 ); 2613 } 2614 2615 return hash_hmac( $algo, $data, $salt ); 2596 2616 } 2597 2617 endif; -
trunk/tests/phpunit/tests/pluggable/signatures.php
r56549 r59578 210 210 'data', 211 211 'scheme' => 'auth', 212 'algo' => 'md5', 212 213 ), 213 214 'wp_hash_password' => array( 'password' ),
Note: See TracChangeset
for help on using the changeset viewer.