我正在使用带有 Auth 和 ACL 组件的 CakePHP 1.2。
在我的用户注册操作中,密码是未经哈希处理的。具体来说,这个表达式:
if ($this->data[ User ][ password ] !=
$this->Auth->password($this->data[ User ][ 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 ;
}
}
}
我做错了什么?