php 我的密码未通过codeigniter的有效验证

vxbzzdmp  于 2022-11-21  发布在  PHP
关注(0)|答案(1)|浏览(125)

目前,我正在尝试查找并修复错误,但无法找到。
我在登录表单上输入我的帐户和密码。
当我输入正确的用户名时,无论我输入错误的密码还是正确的密码,都可以登录

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

有没有人有办法?请帮帮我。谢谢大家

h79rfbju

h79rfbju1#

首先检查您的数据库函数返回的密码是否正确。

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

然后先输入正确的密码和错误的密码,看它返回什么,这样就可以查到bug在哪里了。

相关问题