douyi4991 2013-09-25 00:16
浏览 37

清除密码而不是更新密码/重置密码

I am trying to allow a user to change their password however instead of replacing the old password with new it removes/clears password field in the database. I am just testing interaction with the db therefore I am not yet using a model.

Controller

<?php
class My_account extends CI_Controller {
    public function index(){
        $this->load->view("vChangePassword");
    }

    public function change_password() {

        $this->load->library('form_validation');

        $this->form_validation->set_rules('cur_password','Current Password','required');
        $this->form_validation->set_rules('new_password','New Password','required');
        $this->form_validation->set_rules('con_password','Confirm Password',          'required[matches[new_password]');
        if ($this->form_validation->run()!= true){
            $this->load->view("vChangePassword");
        } else {
            $sql = $this->db->select("*")->from('users')->where('email',$this->session->userdata('email') )->get();
            foreach($sql->result() as $my_info) {
                $db_password = $my_info->password;
                $email = $my_info->email; 
            }
            if(md5($this->input->post('cur_password'))== $db_password){
                $fixed_password = md5($this->input->post('new_password')); 
                $fixed_password ='password';
                $this->db->where('email', $email)->update('users' ,$fixed_password );

                echo "Password has been updated!" ;    
             } else {
                 echo "Password is incorrect!";
             }
        }


    }
}

?>

My View

 <?php
echo form_open(base_url()."index.php/my_account/change_password")?>
<?php echo validation_errors();
?>
<table class=”table table-bordered”>
<tbody>
<tr>
<td><small><?php echo 'Old Password:';?></small></td>
<td><?php echo form_password("cur_password");?></td>
</tr>
<tr>
<td><small><?php echo 'New Password:';?></small></td>
<td><?php echo form_password("new_password");?></td>
</tr>
<tr>
<td><small><?php echo 'Confirm Password:';?></small></td>
<td><?php echo form_password("con_password");?></td>
</tr>
</tbody>
</table>
&nbsp;&nbsp;<div id=”some”style=”position:relative;”><button type=”submit” class=”btn    btn-primary”><i class=” icon-ok-sign icon-white”></i>&nbsp;Submit</button>
<?php
echo form_close();
?>
  • 写回答

2条回答 默认 最新

  • dongnan1989 2013-09-25 00:54
    关注
    $this->db->where('email', $email)->update('users' ,$fixed_password );
    

    This line looks wrong. It looks like you updated the user name instead of the password field.

    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b