在Cakephp中设置Blowfish身份验证错误


Error setting up Blowfish authentication in Cakephp

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

In my 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]。错误是不言自明的,但我不明白为什么它找不到哈希算法,因为我在Auth组件中添加了河豚到authenticate数组。

错误由

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

在User:: beforeave()函数中。

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 )

您似乎正在使用CakePHP 2.2,而blowfish支持仅在2.3中可用。

根据这个,你必须通过AuthComponent::$authenticate设置来配置AuthComponent来使用它:

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

如果你还有问题,欢迎留言。