Advertisement
fabi0

Untitled

Nov 12th, 2013
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.38 KB | None | 0 0
  1. <?php
  2.  
  3. if (!defined('BASEPATH'))
  4.     exit('No direct script access allowed');
  5.  
  6. class VerifyLogin extends CI_Controller {
  7.  
  8.     function __construct() {
  9.         parent::__construct();
  10.         $this->load->model('user', '', TRUE);
  11.     }
  12.  
  13.     function index() {
  14.  
  15.         $this->load->library('form_validation');
  16.  
  17.         $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
  18.         $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_check_database');
  19.  
  20.         if ($this->form_validation->run() == FALSE) {
  21.  
  22.             $this->load->view('login_view');
  23.         } else {
  24.  
  25.             redirect('home', 'refresh');
  26.         }
  27.     }
  28.  
  29.     function check_database($password) {
  30.  
  31.         $username = $this->input->post('username');
  32.  
  33.  
  34.         $result = $this->user->login($username, $password);
  35.  
  36.         if ($result) {
  37.             $sess_array = array();
  38.             foreach ($result as $row) {
  39.                 $sess_array = array(
  40.                     'id' => $row->id,
  41.                     'username' => $row->username
  42.                 );
  43.                 $this->session->set_userdata('logged_in', $sess_array);
  44.             }
  45.             return TRUE;
  46.         } else {
  47.             $this->form_validation->set_message('check_database', 'Invalid username or password');
  48.             return false;
  49.         }
  50.     }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement