dongtuo8170 2014-10-20 09:43
浏览 47
已采纳

如何在codeigniter中创建重置密码功能?

Whenever i run this code, i recieve a blank screen on submission. The code does not seem to work and i'm unsure why. Can anyone see an issue? I've checked it for syntax already mutliple times.

Controller:

public function changepwd(){
    $this->form_validation->set_rules('oldpassword','Old Password','required|trim|xss_clean|callback_change');
    $this->form_validation->set_rules('password1','New Password','required|trim');
    $this->form_validation->set_rules('password2','Confirm Password','required|trim|matches[password1]');

if($this->form_validation->run()= true){
    redirect('admin');
   }else{
$this->form_validation->set_message('change','info is wrong');
redirect('admin');  
}
}

public function change(){
$this->load->view('error_display');
$oldpass = $this->input->post('oldpassword');
if(isset($oldpass)){
    if($this->input->post('password1') == $this->input->post('password2')){

        $session=$this->session->userdata("logged_in");
        $username= $session['username'];

            $query = "SELECT * FROM database where username='$username'";
            $result = $this->db->query($query);
            $row=$result->row();
            $pass = $row->password;
            $s= $row->salt;
            $user_old_pass = sha1($s.$oldpass);

            if($pass == $user_old_pass){
                $new = substr(uniqid(rand(), true), 0, 20);
                $users_password = $this->input->post('pass1');
                $new_password = sha1($new.$user_password);
                $data = array($new,$new_password);  
                $this->update_model->insert_model($data);
                $this->form_validation->set_message('change','saved');
                $this->load->view('admin');

            }else{
                $this->form_validation->set_message('change','<p class="error">Incorrect Password</p>');
                return false;
                redirect('admin');  
            }
    }else{
        $this->form_validation->set_message('change','passwords dont match');
        return false;   
        redirect('admin');
    };

}else{
    $this->form_validation->set_message('change','old password is not entered');
    return false;
    redirect('admin');
}

model:

 function login($data)
    {
    $this->db->update('database', $data);
       }
  • 写回答

1条回答 默认 最新

  • dpsr1670 2014-10-20 09:46
    关注

    your

    if($this->form_validation->run()= true){
    

    should be

       if($this->form_validation->run() == FALSE) {
    

    because you are redirecting every time to 'admin'

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求一下解题思路,完全不懂
  • ¥15 tensorflow
  • ¥15 densenet网络结构中,特征以cat方式复用后是怎么进行误差回传的
  • ¥15 STM32G471芯片spi设置了8位,总是发送16位
  • ¥15 R语言并行计算beta-NTI中tree文件的类型
  • ¥15 如何解读marsbar导出的ROI数据?
  • ¥20 求友友协助弄一下基于STC89C52单片机的声光控制灯原理图
  • ¥15 arduino双向交通灯设计
  • ¥15 有没有会粒子群算法的大能(○゜ε^○)求带不会出收敛图😭
  • ¥15 Matlab读取根元素出错