Cakephp bcrypt保存空字段
我正在尝试为我的cakephp应用程序设置bcrypt。我以前在另一个应用程序上设置过它,这很有效。但是,在基本上将加密代码从一个应用程序复制/粘贴到另一个应用程序之后,它将密码保存为空白 数据库设置正确,密码字段为varchar(225) 我已经得出结论,下面这行代码是导致问题的原因Cakephp bcrypt保存空字段,cakephp,bcrypt,Cakephp,Bcrypt,我正在尝试为我的cakephp应用程序设置bcrypt。我以前在另一个应用程序上设置过它,这很有效。但是,在基本上将加密代码从一个应用程序复制/粘贴到另一个应用程序之后,它将密码保存为空白 数据库设置正确,密码字段为varchar(225) 我已经得出结论,下面这行代码是导致问题的原因 public function beforeSave($options = array()) { if (isset($this->data[$this->alias]['password']
public function beforeSave($options = array()) {
if (isset($this->data[$this->alias]['password'])) {
$hash = Security::hash($this->data['User']['password'], 'blowfish');
$this->data['User']['password'] = $hash;
}
return true;
}
如果我去掉这个beforeSave函数,我的密码将以明文形式正确保存。如果我要取代
$this->data['User']['password'] = $hash;
与
它将正确地将密码保存为testpassword
我的AppController:
public $components = array(
'Session',
'Auth' => array(
'authenticate' =>'Blowfish',
'logoutRedirect' => array('controller'=>'fronts', 'action'=>'index'),
'authorize' => array('Controller')
)
);
我的表格:
<?php echo $this->Session->flash('auth'); ?>
<?php echo $this->Form->create('User'); ?>
<fieldset>
<?php
echo $this->form->input('username', array('placeholder' => 'Username', 'label' => false));
echo $this->form->input('password', array('placeholder' => 'Password', 'label' => false));
echo $this->form->submit('CREATE', array('class' => 'button'));
?>
</fieldset>
<?php echo $this->Form->end(); ?>
beforesave似乎是正确的。我基本上是在用同样的东西。这是我的密码 我也在我的beforefilter中设置了河豚,但在其他方面有问题
$this->Auth->authorize = array('Controller');
$this->Auth->authenticate = array(
'Blowfish' => array(
'userModel' => 'Account',
'fields' => array('username' => 'act_username', 'password' => 'act_password')
)
);
唯一的其他区别是我的表单按钮有这个提交
echo $this->Form->submit('Login', array('id' => 'submit', 'type' => 'submit'));
请注意,从2.4开始,河豚加密正在更改,b仅在2.3中更改:您可以发布或查看已设置的表单吗?也许一个字段的名称是错误的好主意,谢谢你的回答,但它并没有起到多大作用。在数据库中仍然返回空密码您使用的是什么版本?2.2.9。。。我刚刚意识到bcrypt要到2.3才能实现,对吗?该死的呜呜声。我只是下载了上面的版本,假设它是最新的。是否可以在不丢失进度的情况下更新我的版本?编辑:修复了所有问题。谢谢你指出:)
$this->Auth->authorize = array('Controller');
$this->Auth->authenticate = array(
'Blowfish' => array(
'userModel' => 'Account',
'fields' => array('username' => 'act_username', 'password' => 'act_password')
)
);
echo $this->Form->submit('Login', array('id' => 'submit', 'type' => 'submit'));