CakePHP 2:覆盖AuthComponent的“密码”方法
我的目标是为每个用户提供唯一的盐,而不是为每个用户使用Configure :: read(‘Security.salt’).
我知道CakePHP 2.x不再自动密码密码.这允许我对密码执行模型验证,这是非常好的.但是,我没有看到我可以覆盖AuthComponent的“密码”方法.所以即使我可以控制密码在保存到数据库之前是如何进行散列的,所以我无法控制在执行实际登录时密码是如何散列的.从食谱:
我可以做什么来使$this-> Auth-> login()使用自定义的密码哈希方法? 谢谢. 更新:我结束了汉尼拔Lecter博士的回答(创建一个自定义认证对象).以下是如何做到这一点: 旧代码: $this->Auth->authenticate = array('Form' => array('fields' => array('username' => 'email'))); 新代码(将“Form”更改为“Custom”): $this->Auth->authenticate = array('Custom' => array('fields' => array('username' => 'email'))); 创建“app / Controller / Component / Auth / CustomAuthenticate.php”,使其如下所示: <?php App::uses('FormAuthenticate','Controller/Component/Auth'); class CustomAuthenticate extends FormAuthenticate { } 从“lib / Cake / Controller / Component / Auth / BaseAuthenticate.php”复制“_findUser”和“_password”方法,并将它们粘贴到“CustomAuthenticate”类中.然后对“_findUser”方法进行以下两个修改: >从“$conditions”数组中删除此行:$model. ” . $fields [‘password’] => $这 – > _password($密码), 然后对“_password”方法进行以下两个修改: >通过更改保护函数_password($password){保护函数_password($password,$id){ 最后,更新所有出现的AuthComponent :: password以使用与上述相同逻辑的Security :: hash.
你可能创建一个
custom auth object,并哈希密码,但你喜欢.看看
existing auth objects,了解它们的工作原理.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |