小编bfi*_*res的帖子

CakePHP 2.4使用bcrypt登录失败

我正在尝试使用bcrypt实现登录系统.我在User模型的beforeSave()方法上有这个代码:

public function beforeSave($options = array()) {



    if (!$this->id && !isset($this->data[$this->alias][$this->primaryKey])) { // insert
        /*Hash the password*/
        $this->data['User']['password'] = Security::hash($this->data[$this->alias]['password'], 'blowfish');

        /*Set the username the same as the email*/
        $this->data['User']['username'] = $this->data['User']['email'];

    }
    parent::beforeSave($options);
}
Run Code Online (Sandbox Code Playgroud)

此代码在将密码存储到数据库之前成功地对密码进行哈希处理.

对于登录过程,我在视图中有这个表单:

echo $this->Form->create('User', array('action' => 'login'));

    echo $this->Form->input('username', array(
        'class' => 'login-input',
        'placeholder' => $input_username_default_text,
        'id' => 'username',
        'label' => false,
        'div' => false,
        'type' => 'text'
    ));
    echo $this->Form->input('password', array(
        'class' => 'login-input',
        'placeholder' => $input_password_default_text,
        'id' => 'password',
        'label' => false,
        'div' …
Run Code Online (Sandbox Code Playgroud)

php cakephp cakephp-2.4

2
推荐指数
1
解决办法
1263
查看次数

标签 统计

cakephp ×1

cakephp-2.4 ×1

php ×1