使用cakephp的Auth组件和salted密码哈希

时间:2010-06-17 22:57:50

标签: php security cakephp

如何让cakephp的Auth组件创建,使用和存储随机盐和密码?

3 个答案:

答案 0 :(得分:4)

您可以从http://book.cakephp.org/view/566/Change-Hash-Function开始,并将$authenticate变量设置为您的用户模型:

class User extends AppModel {
    function hashPasswords($data) {
        if (isset($data['User']['password'])) {
            //Get the user to get the salt
            $user = $this->findByUsername($data['User']['username']);
            //Let's say you have a "salt" field in your db 
            $data['User']['password'] = md5($data['User']['password'].$user['User']['salt']);
            return $data;
        }
        return $data;
    }
}

答案 1 :(得分:0)

Auth组件中没有此类功能。看看Random String generator CakePHP component

答案 2 :(得分:0)

查看覆盖Auth组件使用的哈希函数,如here所述。