I use a function authentication user login to default so simple login code..
controller/login.php
<?php if(!defined('BASEPATH')) exit ('No Direct script access allowed');
class Login extends CI_Controller{
function __construct()
{
parent::__construct();
$this->load->database();
$this->load->helper('url');
$this->load->model('login_model');
}
public function index()
{
$cek = $this->session->userdata('logged_in');
if(empty($cek))
{
//create Attribut Form
$form['username'] = array('name' => 'username',
'id' => '',
'type' => 'text',
'class' => 'span12',
'autocomplete' => 'off',
'placeholder' => 'Please Insert Username ...'
);
$form['password'] = array('name' => 'password',
'id' => '',
'type' => 'password',
'class' => 'span12',
'autocomplete' => 'off',
'placeholder' => 'Please Insert Password....'
);
$this->form_validation->set_rules('username', 'Username','required');
$this->form_validation->set_rules('password','Password','required');
if($this->form_validation->run() == FALSE)
{
$this->load->view('login',$form);
}
else
{
$user = $this->input->post('username');
$pass = $this->input->post('password');
$this->login_model->getLoginData($user, $pass);
}
}
else
{
header('location:'.base_url().'login/logout');
}
}
public function logout()
{
$cek = $this->session->userdata('logged_in');
if(empty($cek))
{
header('location:'.base_url().'login');
}
else
{
$this->session->sess_destroy();
header('location:'.base_url().'login');
}
}
}
and to load a login_model.php in : models/login_model.php
public function getLoginData($user,$pass)
{
$usr = mysql_real_escape_string($user);
$pwd = sha1(mysql_real_escape_string($pass));
$cek_login = $this->db->get_where('table_login', array('username' => $usr, 'password' => $pwd));
if(count($cek_login->result()) > 0)
{
foreach ($cek_login->result() as $login) {
if($login->jabatan == 'Administrator' && $login->stats== 'Active')
{
foreach($cek_login->result() as $log)
{
$sess_data['logged_in'] = 'YesSayaTelahLogin';
$sess_data['username'] = $log->username;
$sess_data['nama_karyawan'] = $log->full_name;
$sess_data['id_kar'] = $log->id_employee;
$sess_data['jabatan'] = $log->jabatan;
$this->session->set_userdata($sess_data);
}
header('location:'.base_url().'administrator/employee');
}
else
{
$this->session->set_flashdata('result_login','Username Not Registered');
header('location:'.base_url().'login');
}
}
}
else
{
$this->session->set_flashdata('result_login','Your Username Or Password It's Wrong..!!');
header('location:'.base_url().'login');
}
}
I Use a function login in default login_model ... not use a function in grocery_CRUD()