从数组中检索密码值


Retrieve password value from array

我正在尝试将phpass库与现有的身份验证方法集成

public static function authenticate($username, $password)
{
    global $db;
    $username = $db->prep_query($username);
    $password = $db->prep_query($password); // Does not seems like it will be used
    # First step: Retrieve the account based on the user input (email)
    $query_string = "SELECT * FROM users WHERE email = '{$username}' LIMIT 1";
    $query_result = static::find_by_query_string($query_string);
    return !empty($query_result) ? array_shift($query_result) : false;
}

现在返回的记录是(根据print_r($query_result)

Array ( [0] => User Object ( [id] => 7 [password] => $2a$08$qwSjSZ11TUYs5w1L89ppFer2n40HrnjlvaQ00DsUOOvjSYwoEmN4K [email] => test@user.com ) ) 1

我试图检索的是:"$2a$08$qwSjSZ11TUYs5w1L89ppFer2n40HrnjlvaQ00DsUOOvjSYwoEmN4K"

但当我使用$query_result[0][1]$query_result[0]["password]时,我会出现错误。

我在这里错过了什么?如何使用$query_string数组中的密码值?

您访问第一个数组索引,它恰好是一个对象。因此,您需要访问名为password的属性。

$query_result[0]->password