당신은 두 번 where 절을 수행 할 필요가 없습니다.
public function login(){
try
{
$user = $this->db->select()->where()->get(); // mysql query
if(!$user)
throw new Exception("User not found!");
if(!$this->compare_password($this->input->post('password'), $user->password))
throw new Exception("Passwords did not match!");
}
catch(Exception $e)
{
$this->session->set_flashdata('error', $e->getMessage());
log_message('error', $e->getMessage());
redirect('/');
}
//we got this far so everything should be OK
$this->session->set_flashdata('success', 'Login Successfull');
redirect('dashboard');
}
참고 : 당신은 생산 모드에서 이것보다 algorithim 해싱 더 나은 암호를 사용하고자하는 것입니다!
protected function hash_password($password){
return sha1($pw . $this->config->item('encryption_key'));
}
protected function compare_password($pw, $dbpw){
return (sha1($pw . $this->config->item('encryption_key')) === $dbpw)
}
'$ pass '를'md5'(또는 뭔가)하고 싶다고 가정합니다. $ 소금'? –
이 코드는 문제가 해결되지 않았습니까? 쿼리를 실행 한 후,'$ this-> db-> last_query()'를 echo하여 어떤 SQL CodeIgniter가 실행 중인지 확인하십시오. –
그냥 ** $ pass 사이의 공백을 제거하십시오. $ salt **는이 코드에서 내가 싫어하는 유일한 것입니다. – sbaaaang