簡體   English   中英

如何在Codeigniter中設置重置密碼功能?

[英]How can i make a reset password function in codeigniter?

每當我運行此代碼時,提交時我都會收到黑屏。 該代碼似乎無法正常工作,我不確定為什么。 誰能看到一個問題? 我已經檢查了它的語法已經是多倍的時間了。

控制器:

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');
}

模型:

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

你的

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

應該

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

因為您每次都重定向到'admin'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM