Guest User

Untitled

a guest
Jul 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Auth_lib
  4. {
  5.  
  6. function Auth_lib()
  7. {
  8. $this->ci =& get_instance();
  9. }
  10.  
  11. function login($username, $password)
  12. {
  13. $password = md5($password);
  14.  
  15. $this->ci->db->select('user_id');
  16. $this->ci->db->where('user_username', $username);
  17. $this->ci->db->where('user_password', $password);
  18. $this->ci->db->limit(1);
  19.  
  20. //Execute Active Record Query that was just built
  21. $query = $this->ci->db->get('users');
  22.  
  23. // If there is a user found with those credentials then store some vital data into the Session
  24. if ($query->num_rows() > 0) {
  25. $row = $query->row();
  26. $data = array(
  27. 'username' => $username,
  28. 'user_id' => $row->user_id,
  29. 'logged_in' => TRUE//,
  30. );
  31.  
  32. $this->ci->session->set_userdata($data);
  33.  
  34. return TRUE;
  35. } else {
  36. // If the user is not logged in, FALSE must be returned
  37. // An attempt log could be executed here
  38. return FALSE;
  39. }
  40. }
  41.  
  42. function logout()
  43. {
  44. $this->ci->session->set_userdata(array('user_id' => '', 'username' => '', 'status' => '','logged_in' => ''));
  45.  
  46. $this->ci->session->sess_destroy();
  47. return TRUE;
  48. }
  49.  
  50. function is_logged_in()
  51. {
  52. return $this->ci->session->userdata('user_id');
  53. }
  54.  
  55. }
Add Comment
Please, Sign In to add comment