doucheng5209 2013-09-10 12:17
浏览 55

在codeigniter中使用sha1的verrifyin密码出现问题

I am trying to use the sha1 to verify the password that is encrypted in the database using the same procedure. It does not give an error and it does not do anything as well. I presume I am doing something wrong which I do not know.

Model

function check_login ($email, $password) {
        $this->load->database();
        // Query to retrieve the user's details
        // based on the received username and password

        $sha_password = sha1($password);
        $this->db->from('user');
        $this->db->where('email', $email);
        $this->db->where('password', $sha_password);
        $q = $this->db->get()->result();

        // The results of the query are stored in $q.
        // If a value exists, then the user account exists and is validated

        if (is_array($q) && count($q) == 1) {
            // Set the users details into the $details property of this class
            $this->details = $q[0];
            // Call set_session to set the user's session 
            $this->set_session();
            return true;
        }
        return false;
    }

Controller

public function login() {

        $this->form_validation->set_rules('email', 'Email', 'trim|required|xss_clean');
        $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');

        if ($this->form_validation->run() == FALSE) {

            // return main page if submitted form is invalid.

            $this->load->view('abt_login');
        } else {
            $email = $this->input->post('email');
            $password = $this->input->post('password');
            $this->load->model('abt_db');
            $q = $this->abt_db->check_login($email, $password);
            if ($q) {
//                $this->abt_db->set_session($q);
                redirect('index.php/abovetheblues/abt_abovetheblues');
            } else {
                $this->show_login(true);
            }
        }
    }
  • 写回答

1条回答 默认 最新

  • dqlxtv1452 2013-09-10 12:54
    关注

    make some change in your function

        function check_login ($email, $password) {
        $this->load->database();
        $sha_password = sha1($password);
        $this->db->from('user');
        $this->db->where('email', $email);
        $this->db->where('password', $sha_password);
        $q = $this->db->get()->result();
        $num_rows=$q->num_rows();
        if ($num_rows > 0) {
            $this->set_session();
            return true;
        }
        else
        return false;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)