我正在用 cakePhp 3 做一个项目,但我无法登录。 $this->Auth->indetify();
总是返回 false
看别人的类似问题,都建议把我的table.password
放在varchar(255)
数据库中,但这并没有帮助。
数据库表:
CREATE TABLE users (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
person_id BIGINT NOT NULL,
username VARCHAR(50),
password VARCHAR(255),
role VARCHAR(20),
active boolean DEFAULT TRUE NOT NULL
);
UsersControllers 中的函数登录和注销
public function login() {
if ($this->request->is('post')) {
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error(__('User and Password incorrect'));
}
public function logout() {
return $this->redirect($this->Auth->logout());
}
public function beforeFilter(Event $event)
{
parent::beforeFilter($event);
$this->Auth->allow(['index', 'logout', 'add','login']);
}
应用程序 Controller :
public function initialize()
{
parent::initialize();
$this->loadComponent('RequestHandler');
$this->loadComponent('Flash');
$this->loadComponent('Auth',[
'loginRedirect' => [
'controller' => 'Users',
'action' => 'index'
],
'logoutRedirect' => [
'controller' => 'Users',
'action' => 'login'
]
]);
和我的/Users/login.ctp
<div class="users form">
<?= $this->Flash->render('auth') ?>
<?= $this->Form->create() ?>
<fieldset>
<legend><?= __('User and Password') ?></legend>
<?= $this->Form->input('username') ?>
<?= $this->Form->input('password') ?>
</fieldset>
<?= $this->Form->button(__('Login')); ?>
<?= $this->Form->end() ?>
</div>
我遵循了一个教程,这显然是为了工作 =\
最佳答案
这听起来可能很愚蠢,但是密码是在您的数据库中进行哈希处理还是您以纯文本手动写入? 如果不是,请确保它是。
关于php - CakePHP 3.0 登录每次都返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38128622/