dou91855 2018-07-25 06:35
浏览 45
已采纳

什么错误phpmyadmin - count():参数必须是一个数组或一个实现Countable的对象,行号:40

I want to count user in database to login, what wrong whith my code

public function index(){
    //validasi
    $valid = $this->form_validation;

    $valid->set_rules('username', ' Username', 'required',
                array('required'    => 'Username harus diisi'));
    $valid->set_rules('password', 'Password', 'required|min_length[6]',
                array('required'    => 'password harus diisi',
                      'min_length'  => 'Password minimal 6 karakter'));


    if($valid->run()===FALSE){
        //end validasi
        $data = array('title' => 'Login Admin Tempat Ngaji');
        $this->load->view('back-end/login_view', $data, FALSE);
    //cek username dan password
    }else{
        $i              = $this->input;
        $username       = $i->post('username');
        $password       = $i->post('password');
        //cek di database
        $check_login    = $this->admin_model->login($username, $password);

        //jika ada di db
        //jika ada data 1
        if(count($check_login) == 1) { `//row 40`
            $this->session->set_userdata('username', $username);
            $this->session->set_userdata('akses_level', $check_login->akses_level);
            $this->session->set_userdata('id_admin', $check_login->id_admin);
            $this->session->set_userdata('nama', $check_login->nama);
            $this->session->set_userdata('status', $check_login->status);
            redirect(base_url('admin/dashboard'), 'refresh');
        }else{
            //jika tidak cocok error
            $this->session->set_flashdata('msg', 'Username atau password tidak cocok');
            redirect(base_url('admin/login'), 'refresh');

        }

function login

function login
    public function login($username, $password){
        $this->db->select('*');
        $this->db->from('admin');
        $this->db->where(array('username'   => $username,
                                'password'  => sha1($password)));
        $query = $this->db->get();
        return $query->row();
    }

Looking for I saw that some have this error in their code, but I did not find anyone who received it in phpMyAdmin ...

What should I d

  • 写回答

1条回答 默认 最新

  • dougong7850 2018-07-25 07:06
    关注

    Try this:

    MODEL:

    public function login($username, $password){
            $this->db->select('*');
            $this->db->from('admin');
            $this->db->where(array('username'   => $username,
                                    'password'  => sha1($password)));
            $query = $this->db->get();
            if ($query->num_rows() !== 1) {
                return false;
            }
            return $query->row();
        }
    

    CONTROLLER:

        if($check_login) { `//row 40`
            $this->session->set_userdata('username', $username);
            $this->session->set_userdata('akses_level', $check_login->akses_level);
            $this->session->set_userdata('id_admin', $check_login->id_admin);
            $this->session->set_userdata('nama', $check_login->nama);
            $this->session->set_userdata('status', $check_login->status);
            redirect(base_url('admin/dashboard'), 'refresh');
        }else{
            //jika tidak cocok error
            $this->session->set_flashdata('msg', 'Username atau password tidak cocok');
            redirect(base_url('admin/login'), 'refresh');
    
        }
    

    also sha1 like md5 isn't secure (SHA-1 is prone to length extension attacks):

    Warning It is not recommended to use this function to secure passwords, due to the fast nature of this hashing algorithm. See the Password Hashing FAQ for details and best practices.

    http://php.net/manual/en/function.sha1.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证