0

我试图让我的应用程序使用 Blowfish 进行身份验证。这是我到目前为止所设置的。

在我的 AppController 中:

public $components = array(
    'Session',
    'Auth' => array(
        'authenticate' => array(
            'Blowfish' => array(
                'scope' => array(
                    'User.is_active' => true
                )
            )
        )
    )
);

在我的User模型中:

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

我按照此链接设置河豚:http ://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#using-bcrypt-for-passwords 。

我得到的错误是hash(): Unknown hashing algorithm: blowfish [CORE/Cake/Utility/Security.php, line 109]. 该错误是不言自明的,但我不明白为什么它找不到散列算法,因为我将 Blowfish 添加到组件中的authenticate数组中Auth

该错误由

$this->data[$this->alias]['password'] = Security::hash($this->data[$this->alias]['password'], 'blowfish');

在 User::beforeSave() 函数中。

输出print_r(mcrypt_list_algorithms());

Array ( [0] => cast-128 [1] => gost [2] => rijndael-128 [3] => twofish [4] => arcfour [5] => cast-256 [6] => loki97 [7] => rijndael-192 [8] => saferplus [9] => wake [10] => blowfish-compat [11] => des [12] => rijndael-256 [13] => serpent [14] => xtea [15] => blowfish [16] => enigma [17] => rc2 [18] => tripledes )
4

2 回答 2

1

您似乎使用的是 CakePHP 2.2,而河豚支持仅在 2.3 中可用。

于 2013-05-12T17:47:51.570 回答
-1

据此您必须配置 AuthComponent 以通过 AuthComponent::$authenticate 设置使用它:

$this->Auth->authenticate = array(
        'Blowfish' => array(
                'scope' => array('User.active' => 1)
        )
)

如果您仍有问题,请随时发表评论。

于 2013-05-12T04:04:45.847 回答