Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Add type check to hash before passing it to has_equals to prevent warning #8232

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/wp-includes/pluggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2672,7 +2672,13 @@ function wp_check_password( $password, $hash, $user_id = '' ) {

// If the hash is still md5...
if ( strlen( $hash ) <= 32 ) {
$check = hash_equals( $hash, md5( $password ) );
// Ensure both $hash and the md5 of $password are strings before passing them to `hash_equals()`.
if ( is_string( $hash ) && is_string( md5( $password ) ) ) {
$check = hash_equals( $hash, md5( $password ) );
} else {
$check = false;
}

if ( $check && $user_id ) {
// Rehash using new hash.
wp_set_password( $password, $user_id );
Expand Down Expand Up @@ -2702,7 +2708,12 @@ function wp_check_password( $password, $hash, $user_id = '' ) {
$wp_hasher = new PasswordHash( 8, true );
}

$check = $wp_hasher->CheckPassword( $password, $hash );
// Ensure that both $password and $hash are strings before passing them to `CheckPassword()`
if ( is_string( $password ) && is_string( $hash ) ) {
$check = $wp_hasher->CheckPassword( $password, $hash );
} else {
$check = false;
}

/** This filter is documented in wp-includes/pluggable.php */
return apply_filters( 'check_password', $check, $password, $hash, $user_id );
Expand Down
Loading