Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将应用程序密码与wordpress密码匹配_Php_Wordpress - Fatal编程技术网

Php 将应用程序密码与wordpress密码匹配

Php 将应用程序密码与wordpress密码匹配,php,wordpress,Php,Wordpress,我需要将我的应用程序密码与wordpress密码匹配。我把wp_check_密码、wp_hash_密码添加到我自己的代码中,但这没有发生任何事情,我现在的任务是用户将在wordpress中注册帐户,这已经解决了,因为可以使用插件,而现在的问题是我发送给wp_的应用程序密码是MD5,并且也不能使用wordpress密码登录到应用程序。希望有人能帮助我,谢谢。 下面是我的代码: class DbOperations{ private $con; function __construct(){

我需要将我的应用程序密码与wordpress密码匹配。我把wp_check_密码、wp_hash_密码添加到我自己的代码中,但这没有发生任何事情,我现在的任务是用户将在wordpress中注册帐户,这已经解决了,因为可以使用插件,而现在的问题是我发送给wp_的应用程序密码是MD5,并且也不能使用wordpress密码登录到应用程序。希望有人能帮助我,谢谢。 下面是我的代码:

class DbOperations{

private $con; 

function __construct(){

    require_once dirname(__FILE__).'/DbConnect.php';

    $db = new DbConnect();

    $this->con = $db->connect();

}
function wp_hash_password($password) {
global $wp_hasher;

if ( empty($wp_hasher) ) {
    require_once( ABSPATH . WPINC . '/class-phpass.php');
    // By default, use the portable hash from phpass
    $wp_hasher = new PasswordHash(8, true);
}

return $wp_hasher->HashPassword( trim( $password ) );
}
 function wp_check_password($password, $hash, $user_id = '') {
global $wp_hasher;

// If the hash is still md5...
if ( strlen($hash) <= 32 ) {
    $check = hash_equals( $hash, md5( $password ) );
    if ( $check && $user_id ) {
        // Rehash using new hash.
        wp_set_password($password, $user_id);
        $hash = wp_hash_password($password);
    }

    /**
     * Filters whether the plaintext password matches the encrypted password.
     *
     * @since 2.5.0
     *
     * @param bool       $check    Whether the passwords match.
     * @param string     $password The plaintext password.
     * @param string     $hash     The hashed password.
     * @param string|int $user_id  User ID. Can be empty.
     */
    return apply_filters( 'check_password', $check, $password, $hash, $user_id );
}

// If the stored hash is longer than an MD5, presume the
// new style phpass portable hash.
if ( empty($wp_hasher) ) {
    require_once( ABSPATH . WPINC . '/class-phpass.php');
    // By default, use the portable hash from phpass
    $wp_hasher = new PasswordHash(8, true);
}

$check = $wp_hasher->CheckPassword($password, $hash);

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

/*CRUD -> C -> CREATE */

public function createUser($username, $pass, $email){
    if($this->isUserExist($username,$email)){
        return 0; 
    }else{
        $password = wp_hash_password($pass);
        $stmt = $this->con->prepare("INSERT INTO `users` (`id`, `username`, `password`, `email`) VALUES (NULL, ?, ?, ?);");
        $stmt->bind_param("sss",$username,$password,$email);

        if($stmt->execute()){
            return 1; 
        }else{
            return 2; 
        }
    }
}

public function userLogin($username, $pass){
    $password = wp_check_password($pass);
    $stmt = $this->con->prepare("SELECT id FROM users WHERE username = ? AND password = ?");
    $stmt->bind_param("ss",$username,$password);
    $stmt->execute();
    $stmt->store_result(); 
    return $stmt->num_rows > 0; 
}

public function getUserByUsername($username){
    $stmt = $this->con->prepare("SELECT * FROM users WHERE username = ?");
    $stmt->bind_param("s",$username);
    $stmt->execute();
    return $stmt->get_result()->fetch_assoc();
}


private function isUserExist($username, $email){
    $stmt = $this->con->prepare("SELECT id FROM users WHERE username = ? OR email = ?");
    $stmt->bind_param("ss", $username, $email);
    $stmt->execute(); 
    $stmt->store_result(); 
    return $stmt->num_rows > 0; 
}

}