最も簡単なのは、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)."'";