$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();
}
}