Last active
May 10, 2016 16:52
-
-
Save einkoro/11078301 to your computer and use it in GitHub Desktop.
Must-use plugin for WordPress to swap phpass to PHP 5.5's new password_hash and password_verify using bcrypt
This file contains 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: WP PASSWORD_BCRYPT | |
* Plugin URI: http://bitpiston.com/ | |
* Description: Replaces wp_hash_password and wp_check_password's phpass hasher with PHP 5.5's password_hash and password_verify using bcrypt. | |
* Author: BitPiston Studios | |
* Author URI: http://bitpiston.com/ | |
* Version: 1.2 | |
* Licence: BSD | |
*/ | |
function wp_hash_password($password) | |
{ | |
$hash = password_hash($password, PASSWORD_DEFAULT); | |
return $hash; | |
} | |
function wp_check_password($password, $hash, $user_id = '') | |
{ | |
// Check for older passwords and update them | |
if ( substr($hash, 0, 3) == '$P$' ) | |
{ | |
global $wp_hasher; | |
if ( empty($wp_hasher) ) | |
{ | |
require_once(ABSPATH . WPINC . '/class-phpass.php'); | |
$wp_hasher = new PasswordHash(8, true); | |
} | |
$check = $wp_hasher->CheckPassword($password, $hash); | |
if ( $check && $user_id ) | |
{ | |
// Rehash using new hash if they match. | |
wp_set_password($password, $user_id); | |
$hash = wp_hash_password($password); | |
} | |
} | |
$check = password_verify($password, $hash); | |
return apply_filters('check_password', $check, $password, $hash, $user_id); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Superseded by https://github.com/roots/wp-password-bcrypt