0

我正在尝试使用 sha1 来验证使用相同过程在数据库中加密的密码。它不会给出错误,也不会做任何事情。我认为我做错了我不知道的事情。

模型

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

控制器

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

1 回答 1

1

对您的功能进行一些更改

    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;
}
于 2013-09-10T12:54:05.350 回答