1

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

此链接显示了一个示例new SimplePasswordHasher(['hashType' => 'sha256'])->has($data)

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

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

哪种Cake做事方式更多?

4

2 回答 2

2

SimplePasswordHasher来电Security::hash。天哪!

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

于 2014-07-20T16:05:17.853 回答
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;
}
于 2014-07-20T16:32:51.397 回答