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 として正しく保存されます。

私のAppController:

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

The beforesave appears to be correct. I am using the same thing essentially. Here is my code.

I also setup blowfish in my beforefilter, had problems with the other way

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

The only other difference is my form button has this for submit

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

Note this as of 2.4 the blowfish encryption is changing, bcrypt only in 2.3: http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#using-bcrypt-for-passwords

于 2013-08-05T19:01:56.133 に答える