Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function login($username, $password)
- {
- $query = $this->db->select('*')
- ->from('TBL_USER')
- ->where('USERNAME', $username)
- ->where('PASSWORD', $password)
- ->get();
- if($query->num_rows()==1){
- return $query->result();
- }
- else{
- return false;
- }
- }
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- class VerifyLogin extends CI_Controller {
- function __construct()
- {
- parent::__construct();
- $this->load->model('m_sisip','',TRUE);
- $this->load->helper(array('form','html'));
- $this->load->library(array('form_validation','session','security'));
- }
- function index()
- {
- $this->load->library('form_validation');
- $this->form_validation->set_rules('username', 'username', 'trim|required|xss_clean');
- $this->form_validation->set_rules('password', 'password', 'trim|required|xss_clean|callback_check_database');
- if($this->form_validation->run() == FALSE)
- {
- $data['base_url'] = $this->config->item('base_url');
- $this->load->view('login',$data);
- }
- else
- {
- redirect('c_ta/index', 'refresh');
- }
- }
- function check_database($password)
- {
- $username = $this->input->post('username');
- $username = $this->security->xss_clean($username);
- $password = $this->input->post('password');
- $password = $this->security->xss_clean($password);
- $result = $this->m_sisip->login($username, $password);
- if($result)
- {
- $sess_array = array();
- foreach($result as $rows)
- {
- $newdata = array(
- 'id_user' => $rows->ID_USER,
- 'id_role' => $rows->ID_ROLE,
- 'username' => $rows->USERNAME,
- 'password' => $rows->PASSWORD,
- 'nama_user' => $rows->NAMA_USER,
- 'jenis_kelamin'=> $rows->JENIS_KELAMIN,
- 'alamat_user' => $rows->ALAMAT_USER,
- 'notelp_user' => $rows->NOTELP_USER,
- 'email_user' => $rows->EMAIL_USER,
- 'foto_user' => $rows->FOTO_USER,
- 'is_deleted' => $rows->IS_DELETED,
- 'logged_in' => true
- );
- }
- $this->session->set_userdata($newdata);
- return true;
- }
- else
- {
- $this->form_validation->set_message('check_database', 'invalid username or password');
- return false;
- }
- }
- }
- ?>
- <form action="<?php echo site_url('verifylogin');?>"method="POST">
- <fieldset>
- <label class="block clearfix">
- <span class="block input-icon input-icon-right">
- <input type="text" id="username" name="username" class="form-control" placeholder="Username" />
- <i class="ace-icon fa fa-user"></i>
- </span>
- </label>
- <label class="block clearfix">
- <span class="block input-icon input-icon-right">
- <input type="password" id="password" name="password" class="form-control" placeholder="Password" />
- <i class="ace-icon fa fa-lock"></i>
- </span>
- </label>
- <div class="space"></div>
- <div class="clearfix">
- <div class="text-center">
- <button type="submit" class="width-35 pull-justify btn btn-sm btn-danger">
- <i class="ace-icon fa fa-key"></i>
- <span class="bigger-110">Login</span>
- </button>
- </div>
- </div>
- <div class="space-4"></div>
- </fieldset>
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement