我正在尝试使用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);
}
}
}
答案 0 :(得分: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;
}