最简单的方法是调用 Wordpress 函数 wp_hash_password(password)。在这种情况下,您的查询将如下所示:
require_once '/path/to/wp-config.php'; //will load up wordpress, such as if you're doing this from a script
$SQL = "SELECT * FROM wp_users where user_login='".$username."' and user_pass='".wp_hash_password($password)."'";
Wordpress 不使用标准 MD5,而是使用phpass库来散列用户密码。因此,如果您尝试从 Wordpress 之外执行此操作,那么您将需要查看该库。这是使用 phpass 实现 wp_hash_password() 方法的代码:
if ( !function_exists('wp_hash_password') ) :
/**
* Create a hash (encrypt) of a plain text password.
*
* For integration with other applications, this function can be overwritten to
* instead use the other package password checking algorithm.
*
* @since 2.5
* @global object $wp_hasher PHPass object
* @uses PasswordHash::HashPassword
*
* @param string $password Plain text user password to hash
* @return string The hash string of the password
*/
function wp_hash_password($password) {
global $wp_hasher;
if ( empty($wp_hasher) ) {
require_once( ABSPATH . 'wp-includes/class-phpass.php');
// By default, use the portable hash from phpass
$wp_hasher = new PasswordHash(8, TRUE);
}
return $wp_hasher->HashPassword($password);
}
endif;
您可能可以通过遵循相同的模式获得相同的内容:
require_once '/path/to/wp-includes/class-phpass.php';
$my_hasher = new PasswordHash(8, TRUE);
$SQL = "SELECT * FROM wp_users where user_login='".$username."' and user_pass='". $my_hasher->HashPassword($password)."'";