我正在使用带有 Auth 和 ACL 组件的CakePHP 1.2。
在我的用户注册操作中,密码未经过哈希处理。具体来说,这个表达式:
if ($this->data['User']['password'] !=
$this->Auth->password($this->data['User']['confirm_password']))
即使我为password
和提交相同的值,这也评估为真confirm_password
。我知道密码是未散列的,因为当我删除对 的调用时Auth->password
,表达式的计算结果为 false。
我希望 Auth 模块自动散列密码。我究竟做错了什么?
这是我的看法:
<?php
echo $form->create('User', array('action' => 'register'));
echo $form->input('email',
array('after' => $form->error(
'email_unique', 'This email is already registered.')));
echo $form->input('password');
echo $form->input('confirm_password', array('type' => 'password'));
echo $form->end('Register');
?>
这是用户控制器的注册操作:
function register(){
if ($this->data) {
if ($this->data['User']['password'] !=
$this->Auth->password($this->data['User']['confirm_password'])) {
$this->Session->setFlash(__('Password and Confirm Password must match.', true));
$this->data['User']['password'] = '';
$this->data['User']['confirm_password'] = '';
}
else{
$this->User->create();
if ($this->User->save($this->data)){
$this->redirect(array('action' => 'index'), null, true);
}
else {
$this->data['User']['password'] = '';
$this->data['User']['confirm_password'] = '';
$this->Session->setFlash(__('Some problem saving your information.', true));
}
}
}
}
这是我appController
包含Auth
和Acl
模块的地方:
class AppController extends Controller {
var $components = array('Acl', 'Auth');
function beforeFilter(){
if (isset($this->Auth)) {
$this->Auth->allow('display');
$this->Auth->fields =
array(
'username' => 'email',
'password' => 'password');
$this->Auth->authorize = 'actions';
}
}
}
我究竟做错了什么?