为什么CakePHP的验证组件不散列我的密码? [英] Why is the CakePHP authentication component not hashing my password?
问题描述
我使用 CakePHP的 1.2与验证和访问控制列表的组件。
I'm using CakePHP 1.2 with Auth and ACL components.
在我的用户注册行动,密码被散列的到来。具体而言,该前pression:
In my user register action, the password is coming in unhashed. Specifically, this expression:
if ($this->data['User']['password'] !=
$this->Auth->password($this->data['User']['confirm_password']))
这是评估为真,甚至当我提交相同的值密码
和 confirm_password
。我知道密码散列的,因为当我删除调用 Auth-方式>密码
,前pression计算为false
This is evaluating to true, even when I submit identical values for password
and confirm_password
. I know that password is unhashed because when I remove the call to Auth->password
, the expression evaluates to false.
我所期望的验证模块,自动将哈希密码。我在做什么错了?
I expected the Auth module to automagically hash the password. What am I doing wrong?
下面是我的看法:
<?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');
?>
下面是从用户控制器我的寄存器动作:
Here is my register action from the user controller:
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的
,其中包括我的验证
和 ACL
模块:
And here is my appController
where I include the Auth
and Acl
modules:
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';
}
}
}
我在做什么错了?
What am I doing wrong?
推荐答案
除非用户名包含提交的值的CakePHP不会哈希密码。我用电子邮件代替username字段。但是,我通过设置Auth-> fields数组重新映射这些字段。不过,我在做,在AppController中,而不是UserController的。所以移动这一行:
CakePHP won't hash passwords unless username contains a submitted value. I'm replacing the username field with email. However, I remapped those fields by setting the Auth->fields array. However, I was doing that in the appController instead of userController. So moving this line:
$this->Auth->fields = array('username' => 'email', 'password' => 'password');
出的AppController进入UserController的解决了这个问题。
现在的问题变成了为什么我不能复位Auth->在AppController的领域?
out of appController into userController solved it.
Now the question becomes "Why can't I reset the Auth->fields in appController?"
这篇关于为什么CakePHP的验证组件不散列我的密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!