Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. <?php
  2. /**
  3. * login
  4. *
  5. * @return bool
  6. * @author Mathew
  7. **/
  8. public function login($identity, $password, $remember=FALSE)
  9. {
  10. $this->trigger_events('pre_login');
  11.  
  12. if (empty($identity) || empty($password))
  13. {
  14. $this->set_error('login_unsuccessful');
  15. return FALSE;
  16. }
  17.  
  18. $this->trigger_events('extra_where');
  19.  
  20. $query = $this->db->select($this->identity_column . ', username, email, id, password, active, last_login')
  21. ->where($this->identity_column, $identity)
  22. ->limit(1)
  23. ->order_by('id', 'desc')
  24. ->get($this->tables['users']);
  25.  
  26. if($this->is_time_locked_out($identity))
  27. {
  28. //Hash something anyway, just to take up time
  29. $this->hash_password($password);
  30.  
  31. $this->trigger_events('post_login_unsuccessful');
  32. $this->set_error('login_timeout');
  33.  
  34. return FALSE;
  35. }
  36.  
  37. if ($query->num_rows() === 1)
  38. {
  39. $user = $query->row();
  40.  
  41. $password = $this->hash_password_db($user->id, $password);
  42.  
  43. if ($password === TRUE)
  44. {
  45. if ($user->active == 0)
  46. {
  47. $this->trigger_events('post_login_unsuccessful');
  48. $this->set_error('login_unsuccessful_not_active');
  49.  
  50. return FALSE;
  51. }
  52.  
  53. $this->set_session($user);
  54.  
  55. $this->update_last_login($user->id);
  56.  
  57. $this->clear_login_attempts($identity);
  58.  
  59. if ($remember && $this->config->item('remember_users', 'ion_auth'))
  60. {
  61. $this->remember_user($user->id);
  62. }
  63.  
  64. $this->trigger_events(array('post_login', 'post_login_successful'));
  65. $this->set_message('login_successful');
  66.  
  67. return TRUE;
  68. }
  69. }
  70.  
  71. //Hash something anyway, just to take up time
  72. $this->hash_password($password);
  73.  
  74. $this->increase_login_attempts($identity);
  75.  
  76. $this->trigger_events('post_login_unsuccessful');
  77. $this->set_error('login_unsuccessful');
  78.  
  79. return FALSE;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement