Advertisement
Guest User

Untitled

a guest
Apr 7th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. function login($username, $password)
  2. {
  3. $query = $this->db->select('*')
  4. ->from('TBL_USER')
  5. ->where('USERNAME', $username)
  6. ->where('PASSWORD', $password)
  7. ->get();
  8.  
  9. if($query->num_rows()==1){
  10. return $query->result();
  11. }
  12. else{
  13. return false;
  14. }
  15. }
  16.  
  17. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  18.  
  19. class VerifyLogin extends CI_Controller {
  20.  
  21. function __construct()
  22. {
  23. parent::__construct();
  24. $this->load->model('m_sisip','',TRUE);
  25. $this->load->helper(array('form','html'));
  26. $this->load->library(array('form_validation','session','security'));
  27. }
  28.  
  29. function index()
  30. {
  31. $this->load->library('form_validation');
  32.  
  33. $this->form_validation->set_rules('username', 'username', 'trim|required|xss_clean');
  34. $this->form_validation->set_rules('password', 'password', 'trim|required|xss_clean|callback_check_database');
  35.  
  36. if($this->form_validation->run() == FALSE)
  37. {
  38. $data['base_url'] = $this->config->item('base_url');
  39. $this->load->view('login',$data);
  40. }
  41. else
  42. {
  43. redirect('c_ta/index', 'refresh');
  44. }
  45.  
  46. }
  47.  
  48. function check_database($password)
  49. {
  50. $username = $this->input->post('username');
  51. $username = $this->security->xss_clean($username);
  52. $password = $this->input->post('password');
  53. $password = $this->security->xss_clean($password);
  54.  
  55. $result = $this->m_sisip->login($username, $password);
  56.  
  57. if($result)
  58. {
  59.  
  60. $sess_array = array();
  61. foreach($result as $rows)
  62. {
  63. $newdata = array(
  64. 'id_user' => $rows->ID_USER,
  65. 'id_role' => $rows->ID_ROLE,
  66. 'username' => $rows->USERNAME,
  67. 'password' => $rows->PASSWORD,
  68. 'nama_user' => $rows->NAMA_USER,
  69. 'jenis_kelamin'=> $rows->JENIS_KELAMIN,
  70. 'alamat_user' => $rows->ALAMAT_USER,
  71. 'notelp_user' => $rows->NOTELP_USER,
  72. 'email_user' => $rows->EMAIL_USER,
  73. 'foto_user' => $rows->FOTO_USER,
  74. 'is_deleted' => $rows->IS_DELETED,
  75. 'logged_in' => true
  76. );
  77. }
  78.  
  79. $this->session->set_userdata($newdata);
  80. return true;
  81. }
  82. else
  83. {
  84. $this->form_validation->set_message('check_database', 'invalid username or password');
  85. return false;
  86. }
  87. }
  88. }
  89. ?>
  90.  
  91. <form action="<?php echo site_url('verifylogin');?>"method="POST">
  92. <fieldset>
  93. <label class="block clearfix">
  94. <span class="block input-icon input-icon-right">
  95. <input type="text" id="username" name="username" class="form-control" placeholder="Username" />
  96. <i class="ace-icon fa fa-user"></i>
  97. </span>
  98. </label>
  99.  
  100. <label class="block clearfix">
  101. <span class="block input-icon input-icon-right">
  102. <input type="password" id="password" name="password" class="form-control" placeholder="Password" />
  103. <i class="ace-icon fa fa-lock"></i>
  104. </span>
  105. </label>
  106.  
  107. <div class="space"></div>
  108.  
  109. <div class="clearfix">
  110. <div class="text-center">
  111. <button type="submit" class="width-35 pull-justify btn btn-sm btn-danger">
  112. <i class="ace-icon fa fa-key"></i>
  113. <span class="bigger-110">Login</span>
  114. </button>
  115. </div>
  116. </div>
  117. <div class="space-4"></div>
  118. </fieldset>
  119. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement