在Cakephp中设置Blowfish身份验证时出错

时间:2013-05-12 01:43:18

标签: php cakephp

我正在尝试让我的应用程序使用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');
用户:: 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 )

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:-1)

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

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

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