Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.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
$this->;认证->;识别();返回false cakephp3.4_Php_Cakephp_Cakephp 3.4 - Fatal编程技术网

$this->;认证->;识别();返回false cakephp3.4

$this->;认证->;识别();返回false cakephp3.4,php,cakephp,cakephp-3.4,Php,Cakephp,Cakephp 3.4,我无法通过$this->Auth->identify()获取用户详细信息返回false。我没有使用DefaultPasswordHasher。相反,我使用的是LegacyPasswordHasher 下面的代码是为LegacyPasswordHasher编写的: <?php namespace App\Auth; use Cake\Auth\AbstractPasswordHasher; use Cake\Utility\Security; class LegacyP

我无法通过
$this->Auth->identify()获取用户详细信息返回false。我没有使用
DefaultPasswordHasher
。相反,我使用的是
LegacyPasswordHasher

下面的代码是为LegacyPasswordHasher编写的:

<?php     
namespace App\Auth;

use Cake\Auth\AbstractPasswordHasher;
use Cake\Utility\Security;    

class LegacyPasswordHasher extends AbstractPasswordHasher
{

    public static $hashType = null;

    public function hash($string, $type = null, $salt = false) {
        if (empty($type)) {
            $type = static::$hashType;
        }
        $type = strtolower($type);

        if ($type === 'blowfish') {
            return static::_crypt($string, $salt);
        }
        if ($salt) {
            if (!is_string($salt)) {
                $salt = Security::salt();
            }
            $string = $salt . $string;
        }

        if (!$type || $type === 'sha1') {
            if (function_exists('sha1')) {
                return sha1($string);
            }
            $type = 'sha256';
        }

        if ($type === 'sha256' && function_exists('mhash')) {
            return bin2hex(mhash(MHASH_SHA256, $string));
        }

        if (function_exists('hash')) {
            return hash($type, $string);
        }
        return md5($string);
    }

       public function check($password, $hashedPassword)
    {
        return $this->hash($password) === $hashedPassword;
    }

}
这是我在AppController中的
initialize()

    public function initialize()
    {
        parent::initialize();

        $this->loadComponent('RequestHandler');
        $this->loadComponent('Flash');
        $this->loadComponent('Auth', [
        'authenticate' => [
            'Form' => [
                'passwordHasher' => [
                    'className' => 'Legacy',
                ]
            ]
        ]
    ]);
}
这是我在
userscoontrollers
中的login(),返回
false

public function login() {

    if($this->request->is('post')) {
        $user = $this->Auth->identify();
        var_dump($user);
        exit();
    }

}
public function login() {

    if($this->request->is('post')) {
        $user = $this->Auth->identify();
        var_dump($user);
        exit();
    }

}