Gets the hash of the given string.
Description
The default algorithm is md5 but can be changed to any algorithm supported by hash_hmac()
. Use the hash_hmac_algos()
function to check the supported algorithms.
Parameters
$data
stringrequired- Plain text to hash.
$scheme
stringoptional- Authentication scheme (auth, secure_auth, logged_in, nonce).
Default:
'auth'
$algo
stringoptional- Hashing algorithm to use. Default:
'md5'
.Default:
'md5'
Source
function wp_hash( $data, $scheme = 'auth', $algo = 'md5' ) {
$salt = wp_salt( $scheme );
// Ensure the algorithm is supported by the hash_hmac function.
if ( ! in_array( $algo, hash_hmac_algos(), true ) ) {
throw new InvalidArgumentException(
sprintf(
/* translators: 1: Name of a cryptographic hash algorithm. 2: List of supported algorithms. */
__( 'Unsupported hashing algorithm: %1$s. Supported algorithms are: %2$s' ),
$algo,
implode( ', ', hash_hmac_algos() )
)
);
}
return hash_hmac( $algo, $data, $salt );
}
User Contributed Notes
You must log in before being able to contribute a note or feedback.