I have created a change password portal, it keep echo "Old Password Not Match!",but i sure my old password is same with the DB's password, is there any wrong in my controller or model? Hope somebody can help,Thanks!
Below is my controller:
public function chgpass()
{
    $this->load->helper('security');
    $this->form_validation->set_rules('cpassword','Current Password','required|max_length[150]|min_length[6]');
    $this->form_validation->set_rules('npassword','New Password','required|max_length[150]|min_length[6]');
    $this->form_validation->set_rules('copassword','Confirm Password','required|max_length[150]|min_length[6]|matches[npassword]');
    if($this->form_validation->run() == false){
        $this->load->view('chgpass');
    }else{
        //update data
        $data = array(
            'password' => md5($this->input->post('npassword'))
        );
        //check old password
        $result = $this->Form_model->Check_Old_Password($this->session->userdata('USER_ID'),md5($this->input->post('cpassword')));
        if($result > 0 AND $result === true){
            //update user data
            $result = $this->Form_model->Update_User_Data($this->session->userdata('USER_ID'),$data);
            if($result > 0){
                echo "Password Changed!";
                //$this->session->set_flashdata('success','Password Changed!');
                //redirect(base_url() . 'main/login');
            }else{
                echo "Password Not Changed!";
                //$this->session->set_flashdata('error','Password Not Changed!');
                //redirect(base_url() . 'main/chgpass');
            }
        }else{
            echo "Old Password Not Match!";
            //$this->session->set_flashdata('error','Password Not Changed!');
            //redirect(base_url() . 'main/chgpass');
        }
    }
}
Below is my model:
public function Update_User_Data($user_id,$data){
    $this->db->set($data);
    $this->db->where('id',$user_id);
    $this->db->update('users');
    if($this->db->affected_rows() > 0)
        return true;
    else
        return false;
}
public function Check_Old_Password($user_id,$cpassword){
    $this->db->where('id',$user_id);
    $this->db->where('password',$cpassword);
    $query = $this->db->get('users');
    if($query->num_rows() > 0)
        return true;
    else
        return false;
}
 
    