php – 仅填写字段时才更新密码
发布时间:2020-12-13 21:44:23 所属栏目:PHP教程 来源:网络整理
导读:我的看法: tr tdUsername/td td?php echo $this-Form-input('User.username',array('label' = '')); ?/td /tr tr tdPassword/td td?php echo $this-Form-password('User.password',array('label' = '','value'='')); ?/td /tr 我的控制器: function edit($
我的看法:
<tr> <td>Username</td> <td><?php echo $this->Form->input('User.username',array('label' => '')); ?></td> </tr> <tr> <td>Password</td> <td><?php echo $this->Form->password('User.password',array('label' => '','value'=>'')); ?></td> </tr> 我的控制器: function edit($id = null) { $this->User->id = $id; $data = $this->data; # print_r($data); if (empty($data)) { $this->data = $this->User->read(); } else { if ($this->User->save($data)) { $this->Session->setFlash('The user details have been updated.'); $this->redirect(array('action' => 'index')); } } } 在我使用空白密码提交表单时,数据库中的哈希值仍会发生变化.如果填写了新密码,我该如何才更新密码哈希. 谢谢. 编辑:$data [‘用户’] [‘密码’]始终是一个哈希,永远不会空! 解决方法
CakePHP 1.3自动散列密码字段. CakePHP 2.0没有.
您有几个选择(在我看来,从最差到最好): >重命名您的字段并在保存之前进行交换 if ($data['User']['new_password'] != '') { $data['User']['password'] = $this->Auth->password($data['User']['new_password']); } >在等式检查中散列字符串 if ($data['User']['password'] == $this->Auth->password('')) { unset($data['User']['password']); } >将散列函数更改为不散列空密码的函数[请参阅book以获取配置]: function hashPasswords($data) { if (!empty($this->data['User']['password'])) { $this->data['User']['password'] = $this->Auth->password($this->data['User']['password']); } return $data; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |