Created
May 6, 2025 17:25
-
-
Save sc0ttkclark/af47120fee48e65228bc765ab4c41f3f to your computer and use it in GitHub Desktop.
WordPress 6.8.x has new hashing that can be brittle with multisite and object caching. Logging into main site may upgrade the existing password but then hashing could become invalid on other sites. This is NOT a long term solution, you should investigate your object caching issues.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Auto rehash password if needed for multisite | |
Plugin URI: https://www.scottkclark.com/ | |
Description: WordPress 6.8 has new hashing that can be brittle with multisite. Logging into main site may upgrade the existing password but then hashing could become invalid on other sites. | |
Version: 1.0 | |
Author: Scott Kingsley Clark | |
Author URI: https://www.scottkclark.com/ | |
This program is free software; you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation; either version 2 of the License, or | |
(at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program; if not, write to the Free Software | |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
*/ | |
add_filter( 'check_password', static function ( $check, $password, $hash, $user_id ) { | |
static $checking = false; | |
if ( $checking || $check || empty( $user_id ) ) { | |
return $check; | |
} | |
if ( wp_password_needs_rehash( substr( $hash, 3 ), $user_id ) ) { | |
die( 'password needs rehash' ); | |
wp_set_password( $password, $user_id ); | |
$checking = true; | |
$check = wp_check_password( $password, $hash, $user_id ); | |
$checking = false; | |
} | |
return $check; | |
}, 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment