php - CakePHP 3.0 登录每次都返回 false

标签 php mysql cakephp cakephp-3.0

我正在用 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/

相关文章:

php - 如何使用 PHP 在 LAMP 服务器上创建具有所有者权限的目录?

c# - 如何检查程序是否运行以及用户是否存在?

mysql - 保护 MySQL 根密码?

php - 在将现有的 php 应用程序移植到 CakePHP 时,如何为模型使用非标准表/列名称?

php - Cakephp 和 iOS 10.3.2

php - 这是保存上传文件的安全方法吗?

php - 无法通过 Symfony 2.8 表单上传上传文件

php - 如何获取分段 URL cakephp 3

php - SELECT PDO 准备语句中的 SELECT

mysql - 如何使用 $this->request->params 从 URL 获取值