php - My password didn't pass valid authentication in codeigniter

Currently I'm trying to find and fix the error but can't.

I enter my account and password on the login form.

When I enter the correct username and whether I enter the wrong password or the correct password, everything can be logged in


    public function dangnhap(){
        $this->load->library('form_validation');
        $this->form_validation->set_rules('username', 'T?�i kho???n', 'required|min_length[6]|max_length[32]');
        $this->form_validation->set_rules('password', 'M??�t kh??�u', 'required|min_length[6]|max_length[32]');
        if($this->form_validation->run() ==TRUE){
            $username = $_POST['username'];
            $password = md5($_POST['password']);
            if($this->Mcustomer->customer_login($username, $password)!=FALSE){
                $row = $this->Mcustomer->customer_login($username, $password);
                $this->session->set_userdata('sessionKhachHang',$row);
                $this->session->set_userdata('id',$row['id']);
                $this->session->set_userdata('email',$row['email']);
                $this->session->set_userdata('sessionKhachHang_name',$row['fullname']);
                if($this->session->userdata('cart')){
                    redirect('gio-hang','refresh');
                }else{
                    redirect('thong-tin-khach-hang','refresh');
                }
            }else{
                $this->data['error']='T?�i kho???n ho??�c m??�t kh??�u kh??ng ch?�nh x??c';
                $this->data['title']='????ng nh??�p t?�i kho???n';
                $this->data['view']='dangnhap';
                $this->load->view('frontend/layout',$this->data);
            }
        }else{
            $this->data['title']='Smart store - ????ng nh??�p t?�i kho???n';
            $this->data['view']='dangnhap';
            $this->load->view('frontend/layout',$this->data);
        }     
    }

Does anyone have a way? please help me. Thank you so much everyone

Answer

Solution:

First check what your database function is returning with correct password and wrong password by this

public function dangnhap(){
    $this->load->library('form_validation');
    $this->form_validation->set_rules('username', 'T?�i kho???n', 'required|min_length[6]|max_length[32]');
    $this->form_validation->set_rules('password', 'M??�t kh??�u', 'required|min_length[6]|max_length[32]');
    if($this->form_validation->run() ==TRUE){
        $username = $_POST['username'];
        $password = md5($_POST['password']);
        $row = $this->Mcustomer->customer_login($username, $password);
        echo print_r($row)
    }

and then first input right password and wrong password and see what it returns. In this way you can check where is the bug.

Source