我'm new to CakePHP, and I' m使用版本2.8.5 . 我已按照教程添加身份验证到我的网站,如下所示:http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html,但我在尝试登录时遇到问题 .

我可以添加新用户,但每当我尝试登录时,它返回false,我得到:

无效的用户名或密码,请重试 .

我也得到:

警告(512):无效的盐:针对河豚的pass01请访问http://www.php.net/crypt并阅读有关建造河豚盐的相应部分 . [CORE / Cake / Utility / Security.php,第323行]

(pass01是密码) . 我已经按照本教程的说明完全关注了河豚散列,但是我的数据库中的密码似乎没有经过哈希处理(它们只是按原样显示) .

User.php

App::uses('AppModel', 'Model');
App::uses('BlowfishPasswordHasher', 'Controller/Component/Auth');

class User extends AppModel {
    public $validate = array(
        'username' => array(
            'required' => array(
                'rule' => 'notBlank',
                'message' => 'A username is required'
            )
        ),
        'password' => array(
            'required' => array(
                'rule' => 'notBlank',
                'message' => 'A password is required'
            )
        ),
        'role' => array(
            'valid' => array(
                'rule' => array('inList', array('admin', 'author')),
                'message' => 'Please enter a valid role',
                'allowEmpty' => false
            )
        )
    );

    public function beforeSave($options = array()) {
        if (isset($this->data[$this->alias]['password'])) {
            $passwordHasher = new BlowfishPasswordHasher();
            $this->data[$this->alias]['password'] = $passwordHasher->hash(
                $this->data[$this->alias]['password']
            );
        }
        return true;
    }
}

来自 UsersController.php 的登录功能

public function login() {
    if ($this->request->is('post')) {
        if ($this->Auth->login()) {
            return $this->redirect($this->Auth->redirectUrl());
            }
        $this->Flash->error(__('Invalid username or password, try again'));
    }
}

login.ctp

<div class="users form">
<?php echo $this->Flash->render('auth'); ?>
<?php echo $this->Form->create('User'); ?>
    <fieldset>
        <legend>
            <?php echo __('Please enter your username and password'); ?>
        </legend>
        <?php echo $this->Form->input('username');
        echo $this->Form->input('password');
    ?>
    </fieldset>
<?php echo $this->Form->end(__('Login')); ?>
</div>

我查看了所有类似的问题,但没有一个解决方案似乎对我有用 . 我真的很感激任何帮助 .