代码之家  ›  专栏  ›  技术社区  ›  Malfist

使用cakephp的Auth组件和salt密码散列

  •  3
  • Malfist  · 技术社区  · 15 年前

    如何让cakephp的Auth组件创建、使用和存储带有密码的随机salt?

    3 回复  |  直到 15 年前
        1
  •  4
  •   codegy    15 年前

    你可以从这里开始 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;
        }
    }
    
        2
  •  0
  •   bancer    15 年前

    Auth组件中没有这样的功能。看一看 Random String generator CakePHP component .

        3
  •  0
  •   deceze    15 年前

    研究如何重写Auth组件使用的哈希函数,如下所述 here .