CakePHP在添加到MySQL之前不哈希密码

CakePHP在添加到MySQL之前不哈希密码,php,cakephp,authentication,Php,Cakephp,Authentication,外接程序UsersController.php public function add() { if ($this->request->is('POST')) { if ($this->confirmPass()) { //Want false if (!$this->validateSQL('username', 'add')) { $this->Session

外接程序UsersController.php

public function add() {
    if ($this->request->is('POST')) {
        if ($this->confirmPass()) {
            //Want false
            if (!$this->validateSQL('username', 'add')) {
                $this->Session->write('User.username', strtolower('User.username'));
                //Want false
                if (!$this->validateSQL('email', 'add')) {
                    $this->Session->write('User.email', strtolower('User.email'));
                    $this->User->create();
                    if ($this->User->save($this->request->data)) {
                        $this->Session->setFlash(__('Your account has been created'), 'flash_success', array('class' => 'success'), 'success');
                        $this->redirect(ACCOUNT_LOG);
                    } else {
                        $this->Session->setFlash(__('Your account could not be created'), 'flash_failure', array('class' => 'failure'), 'failure');
                    }
                } else {
                    $this->Session->setFlash(__('E-mail already in use'), 'flash_failure', array('class' => 'failure'), 'failure');
                }
            } else {
                $this->Session->setFlash(__('Username already in use'), 'flash_failure', array('class' => 'failure'), 'failure');
            }
        }
    }
}
validateSQL只调用检查用户名和/或电子邮件字段以查看它们是否存在(我将它们留在控制器中,因为我想先解决这个问题,我知道我需要将它们移动到模型中)

confirmPass仅比较视图中的字段password和confirmPassword,返回true或false

在User.php中保存之前

public function beforeSave($options = array()) {
        if (isset($this->request->controller->data[$this->alias]['password'])) {
            $this->request->controller->data[$this->alias]['password'] = AuthComponent::password($this->request->controller->data[$this->alias]['password']);
        }
        return true;
}
昨天一切都很顺利。所有值仍保存到正确的表中,只是没有对密码进行哈希运算(md5+salt)。是否有人知道这是AuthComponent的已知或常见问题

如果我从模型中删除isset:

注意(8):试图获取非对象的属性[APP/Plugin/Account/Model/User.php,第65行]

注意(8):试图获取非对象的属性[APP/Plugin/Account/Model/User.php,第65行]

注意(8):间接修改重载属性User::$request无效[APP/Plugin/Account/Model/User.php,第65行]

使用此选项:

public function beforeSave($options = array()) {
    if (isset($this->data[$this->alias]['password'])) {
        $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
    }
    return true;
}
原因:
在模型中,您只需要
$this->data
,而不需要
$this->request->controller->data

您的
$this->validateSQL()
与正在进行的所有奇怪会话内容的部分看起来不太干净。这就是模型中的save()和validation通常的用途。我注意到我将把它们迁移到模型中。由于我将其用作插件,save()并不能完全满足我的需要,而且我是Cake新手,所以我首先用PHP编写了它,然后将迁移到完整的Cake语法,所有这些都不会修改基本库。这是cakephp 2.0还是3.0?@user1767754 2;3直到2015年3月才向公众开放。这个问题发布于2013年。谢谢。我忽略了这一部分,因为我认为我没有改变任何东西。可能发生在我将粘贴的部分复制到彼此的顶部时。