Cakephp 2.5x密码散列。安全类或SimplePasswordHasher?

时间:2014-07-20 16:01:10

标签: cakephp cakephp-2.5

我正在寻找可以加密该应用程序独有的应用程序密码的选项。例如,如果salt更改了应用程序的Security.salt通常是唯一的,那么同一个数据库将无法工作。

This link显示了new SimplePasswordHasher(['hashType' => 'sha256'])->has($data)

的示例

然而,当我检查安全类的Api时,我看到this function这是一个静态函数,我可以提供sha256和默认salt为true。我没有使用河豚。

AuthComponent::password()已被弃用,因此请不要建议。

哪种更Cake做事方式?

2 个答案:

答案 0 :(得分:2)

SimplePasswordHasher来电Security::hash。天哪!

价: http://api.cakephp.org/2.5/source-class-SimplePasswordHasher.html#33-42

答案 1 :(得分:0)

在您的身份验证模型中:

public function beforeSave($options = array()) {
    parent::beforeSave();
    if (!empty($this->data['Model']['password'])) {
        $this->data['Model']['password'] = Security::hash($this->data['Model']['password'], 'sha256', true);
    }
    return true;
}