所以,我环顾四周,并检查了SO。我的问题类似于这个:Why is the CakePHP authentication component not hashing my password?,除了我不能得到它的工作。为什么不是我的密码哈希?
我的密码在注册时取消了。
在我的用户控制器:
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('register', 'logout');
$this->Auth->fields = array('username' => 'email', 'password' => 'password');
}
查看:
<?php echo $this->Form->create('User'); ?>
<fieldset>
<?php
echo $this->Form->input('email');
echo $this->Form->input('password');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit'));?>
而且我对email
领域的一些验证。问题是,密码以明文形式存储。我以为 Auth->fields
行应该照顾到这一点,但事实并非如此。我知道CakePHP只有散列,如果username
和password
在$data
都填充,但我清楚地重新映射它,所以它应该散列正确?
噢GOSH。难怪!这是否意味着Auth->字段现在是无用的? – Strawberry 2012-04-08 03:38:43
当你的用户登录时,Auth组件仍然在使用它来验证密码,你只需要手动对其进行哈希:) – 2012-04-08 03:53:27
我推荐使用一种行为来保持代码DRY:http://www.dereuromark.de/2011/ 8月25日/工作与-密码功能于CakePHP的/ – mark 2012-04-08 09:54:31