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

如何在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
    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'

    点赞 评论

相关推荐