Authenticatication checking in CodeIgniter

Wanna protect your website from unauthorized ppl. You can use session library to check authentication in CI.
At first you have to create a model for login check:

<?php
class Login_model extends Model
{
function Login_model()
{
parent::Model();
$this->load->library(’session’);
}
function checkAuth($uName,$pass){
$this->db->select(‘*’);
$this->db->where(‘user=’,$uName);
$this->db->where(‘pass=’,md5($pass));
$this->db->where(‘enabled=’,1);
$query = $this->db->get(‘your_users_table’);
//echo $this->db->last_query();
if($query->num_rows()>0){
$data = $query->row_array();
$sessionArray = array( ‘uid’=>$data['ID'],
‘role’=>$data['your_group'],
‘name’=>$data['firstname'].’ ‘.$data['surname'],
‘logged_in’=>TRUE
);
$this->session->set_userdata($sessionArray);
$log=array(‘user_id’=>$this->session->userdata(‘uid’),
‘action_type’=>’LOGIN’,
‘item_type’=>’USER’,
‘time’=>time());
//echo $this->db->last_query();
$this->log_message($log);
return TRUE;
}else{
return FALSE;
}
}
public function check_session()
{
if ($this->session->userdata(‘uid’) AND $this->session->userdata(‘logged_in’)==’TRUE’) {
return TRUE;
} else {
return FALSE;
}
}
public [...]