identify()方法没有';t在CakePHP 3上散列密码?

identify()方法没有';t在CakePHP 3上散列密码?,cakephp,hash,login,cakephp-3.0,Cakephp,Hash,Login,Cakephp 3.0,我制作了一个简单的日志系统,但它没有登录(CakePHP3.3)。密码以散列方式保存,例如: $2y$10$tKUu6KUzrHwqTR5FD0YpaegFHkaoFOWViAtvijJpSQxxJ.E1WFPMu 登录操作无法识别用户。我的控制器和操作: UsersController.php: public function login() { if ($this->request->is('post')) { debug($this->request-&

我制作了一个简单的日志系统,但它没有登录(CakePHP3.3)。密码以散列方式保存,例如:

$2y$10$tKUu6KUzrHwqTR5FD0YpaegFHkaoFOWViAtvijJpSQxxJ.E1WFPMu
登录操作无法识别用户。我的控制器和操作:

UsersController.php:

public function login()
{
    if ($this->request->is('post')) {
    debug($this->request->data);
        debug($this->Auth->identify());
        $user = $this->Auth->identify();
        if ($user) {
            $this->Auth->setUser($user);
            return $this->redirect($this->Auth->redirectUrl());
        } else {
            $this->Flash->error(__('Username or password is incorrect'), [
                'key' => 'auth'
            ]);
        }
    }
}
public function initialize()
{
    parent::initialize();

    $this->loadComponent('RequestHandler');
    $this->loadComponent('Flash');

    //$this->loadComponent('Security');
    //$this->loadComponent('Csrf');

    $this->loadComponent('Auth', [
        'authenticate', [
            'Form' => [
                'fields' => ['username'=>'email', 'password'=>'password'],
                'userModel' => 'Users',
                'passwordHasher' => 'Default'
            ]
        ],
        'loginAction' => [
            'controller' => 'Users',
            'action' => 'login'
        ],
        'loginRedirect' => ['controller'=>'Users', 'action'=>'dashboard'],
        'logoutRedirect' => ['controller'=>'Users', 'action'=>'login'],
        'authError' => __('You do not have permission to access.'),
        'storage' => 'Session'
    ]);
}
AppController.php:

public function login()
{
    if ($this->request->is('post')) {
    debug($this->request->data);
        debug($this->Auth->identify());
        $user = $this->Auth->identify();
        if ($user) {
            $this->Auth->setUser($user);
            return $this->redirect($this->Auth->redirectUrl());
        } else {
            $this->Flash->error(__('Username or password is incorrect'), [
                'key' => 'auth'
            ]);
        }
    }
}
public function initialize()
{
    parent::initialize();

    $this->loadComponent('RequestHandler');
    $this->loadComponent('Flash');

    //$this->loadComponent('Security');
    //$this->loadComponent('Csrf');

    $this->loadComponent('Auth', [
        'authenticate', [
            'Form' => [
                'fields' => ['username'=>'email', 'password'=>'password'],
                'userModel' => 'Users',
                'passwordHasher' => 'Default'
            ]
        ],
        'loginAction' => [
            'controller' => 'Users',
            'action' => 'login'
        ],
        'loginRedirect' => ['controller'=>'Users', 'action'=>'dashboard'],
        'logoutRedirect' => ['controller'=>'Users', 'action'=>'login'],
        'authError' => __('You do not have permission to access.'),
        'storage' => 'Session'
    ]);
}
User.php实体:

class User extends Entity
{
protected $_accessible = [
    '*' => true,
    'id' => false
];

protected $_hidden = [
    'password'
];

protected function _setPassword($password) {
    return (new DefaultPasswordHasher)->hash($password);
}
}
login.ctp:

<h1>login</h1>
<?php
echo $this->Flash->render();
echo $this->Flash->render('auth');

echo $this->Form->create();
echo $this->Form->input('email');
echo $this->Form->input('password');
echo $this->Form->button('entrar');
echo $this->Form->end();
登录

我发现了问题所在。loadComponent上的数组格式。 正确的格式是:

'authenticate' => [
                'Form' => [

验证字段大小是否设置为255(varchar) 散列应该如下所示:

“$2y$10$i4Jnip3WBBxyb7gkm.WjoOe200XSMz/MGL9oZCeupDaeQ0I0fuba6”