在codeigniter上更改密码

时间:2016-05-31 09:58:53

标签: php codeigniter

我试图更改密码功能,但没有任何反应。我实际上改编了codeigniter change password代码但是没有发生任何事情。我附上代码,任何人都会感激不尽。

控制器 -

function change_password_process()
    {
        $this->load->view('ubahpassword_view');
        $this->load->library('form_validation');
        $this->load->library('session');
        $this->form_validation->set_rules('pass_lama','Password Lama','trim|required|min_length[4]|max_length[32]');
        $this->form_validation->set_rules('pass_baru','Password Baru','trim|required|min_length[4]|max_length[32]');
        $this->form_validation->set_rules('ulangpass_baru','Ulangi Password Baru','trim|required|min_length[4]|max_length[32]|matches[pass_baru]');

        if ($this->form_validation->run() == FALSE)
        {
            redirect('ubahpassword');       
        }
        else 
        {
            $query = $this->rekammedis_model->change_password();
            redirect('ubahpassword');
        }
    }

模特 -

function change_password()
    {   
        $this->db->select('id');
        $this->db->where('username', $this->session->userdata('username'));
        $this->db->where('id', $this->session->userdata('id'));
        $this->db->where('password', md5($this->input->post('pass_lama')));
        $query = $this->db->get('user');   

        if ($query->num_rows() > 0)
        {
            $row = $query->row();
            if($row->id === $this->session->userdata('id'))
            {
                $data = array(
                  'password' => md5($this->input->post('pass_lama'))
                );

                $this->db->where('username', $this->session->userdata('username'));
                $this->db->where('password', md5($this->input->post('pass_lama')));

                    if($this->db->update('user', $data)) 
                    {
                        return "Password berhasil diganti!";
                    }

                    else
                    {
                        return "Terdapat kesalahan, password tidak terganti";
                    }
            }

            else
            {
                return "Terdapat kesalahan, password tidak terganti";
            }


        }

        else
        {
            return "Password lama salah";
        }

    }

1 个答案:

答案 0 :(得分:1)

假设baru意味着新的,而喇嘛意味着旧的。

您使用旧密码更改旧密码( pass_baru

所以替换

 $data = array('password' => md5($this->input->post('pass_lama')));

 $data = array('password' => md5($this->input->post('pass_baru')));


<强>更新
发现另一个错误

if ($this->form_validation->run() == FALSE)
{
    redirect('ubahpassword');    
}

您无法重定向,如果您这样做,则无法在此处进行验证。
在这里加载您的视图。如果不起作用,还要更新上面的代码