0
我試圖用POST和驗證但是我UsersController中失敗返回FALSE功能 「這 - $> Auth->確定()」CakePHP的3.X登錄與POST + AUTH失敗
這裏有登錄從AppController中我的設置,查看
AppController的
public function initialize() {
parent::initialize();
$this->loadComponent('Flash');
$this->loadComponent('Auth');
$this->loadComponent('Cookie');
}
function beforeFilter(Event $event) {
$this->Auth->allow('add');
$this->Auth->config('authorize','Controller',true);
$this->Auth->config('authenticate', ['Form' => ['fields' => ['username' => 'username', 'password' => 'password']]]);
$this->Auth->config('logoutRedirect', 'Homes/index',true);
$this->Auth->config('loginRedirect', 'Homes/index',true);
$this->Auth->config('loginAction', 'Users/login',true);
$this->Auth->config('loginError', 'Usuário e/ou senha incorreto(s)',true);
$this->Auth->config('authError', 'Você precisa fazer login para acessar esta página',true);
$this->Auth->config('userModel', 'Users',true);
}
UsersController
public function login() {
if ($this->request->is('post')) {
/* Here return FALSE */
if ($this->Auth->identify()) {
$this->Session->setFlash(__('Welcome, ' . $this->Auth->user('username')));
} else {
$this->Auth->flash('Login errado');
}
}
}
兩login.ctp
<?= $this->Form->create(); ?>
<?php // $this->Form->create('Users'); ?>
<fieldset>
<legend><?= __('Login') ?></legend>
<?php
echo $this->Form->input('username');
echo $this->Form->input('password');
?>
</fieldset>
<?= $this->Form->button(__('Login')) ?>
<?= $this->Form->end() ?>
表的MySQL 用戶名和密碼VARCHAR 200
您的密碼是否被散列並保存正確? –
debug($ this-> request-> data());在您的登錄控制器,並與您的數據庫的密碼進行比較 – CoolLife