0

我正在尝试为我的 cakephp 应用程序设置 bcrypt。我之前在另一个应用程序上设置过它,并且有效。但是,在基本上将加密代码从一个应用程序复制/粘贴到另一个应用程序之后,它将密码保存为空白。

数据库设置正确,密码字段为 varchar(225)。

我得出的结论是以下代码行是导致问题的原因;

public function beforeSave($options = array()) {
    if (isset($this->data[$this->alias]['password'])) {
        $hash = Security::hash($this->data['User']['password'], 'blowfish');
        $this->data['User']['password'] = $hash;
    }
    return true;
}

如果我要取出这个 beforeSave 功能,我的密码将正确保存为明文。如果我要更换

$this->data['User']['password'] = $hash;

$this->data['User']['password'] = 'testpassword';

它会正确地将密码保存为 testpassword。

我的应用控制器:

public $components = array(
    'Session',
    'Auth' => array(
        'authenticate' =>'Blowfish',
        'logoutRedirect' => array('controller'=>'fronts', 'action'=>'index'),
        'authorize' => array('Controller')
    )
);

我的表格:

<?php echo $this->Session->flash('auth'); ?>
<?php echo $this->Form->create('User'); ?>
<fieldset>
    <?php 
        echo $this->form->input('username', array('placeholder' => 'Username', 'label' => false));
        echo $this->form->input('password', array('placeholder' => 'Password', 'label' => false));
        echo $this->form->submit('CREATE', array('class' => 'button')); 
    ?>
</fieldset>
<?php echo $this->Form->end(); ?>

尝试登录时,虽然我知道它不起作用,但我收到此错误

Authentication adapter Blowfish was not found.
4

1 回答 1

1

之前的保存似乎是正确的。我本质上使用的是相同的东西。这是我的代码。

我还在我的前置过滤器中设置了河豚,其他方式有问题

$this->Auth->authorize = array('Controller');
$this->Auth->authenticate = array(
   'Blowfish' => array( 
      'userModel' => 'Account',
      'fields' => array('username' => 'act_username', 'password' => 'act_password')
   )
);

唯一的另一个区别是我的表单按钮有这个提交

echo $this->Form->submit('Login', array('id' => 'submit', 'type' => 'submit'));

请注意,从 2.4 开始,河豚加密正在发生变化,bcrypt 仅在 2.3 中:http: //book.cakephp.org/2.0/en/core-libraries/components/authentication.html#using-bcrypt-for-passwords

于 2013-08-05T19:01:56.133 回答