Advertisement
Guest User

PHP & SQL

a guest
Dec 15th, 2020
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. public function find($user = null) {
  2. if ($user) {
  3. $field = (is_numeric($user)) ? 'id' : 'username';
  4. $data = $this->_db->get('users', array($field, '=', $user));
  5.  
  6. if ($data->count()) {
  7. $this->_data = $data->first();
  8. return true;
  9. }
  10. }
  11. return false;
  12. }
  13.  
  14. public function login($username = null, $password = null, $remember = false) {
  15.  
  16. if (!$username && !$password && $this->exists()) {
  17. Session::put($this->_sessionName, $this->data()->id);
  18. } else {
  19. $user = $this->find($username);
  20.  
  21. if ($user) {
  22. if ($this->data()->password === Hash::make($password, $this->data()->salt)) {
  23. Session::put($this->_sessionName, $this->data()->id);
  24.  
  25. if ($remember) {
  26. $hash = Hash::unique();
  27. $hashCheck = $this->_db->get('users_session', array('user_id', '=', $this->data()->id));
  28.  
  29. if (!$hashCheck->count()) {
  30. $this->_db->insert('users_session', array(
  31. 'user_id' => $this->data()->id,
  32. 'hash' => $hash
  33. ));
  34. } else {
  35. $hash = $hashCheck->first()->hash;
  36. }
  37.  
  38. Cookie::put($this->_cookieName, $hash, Config::get('remember/cookie_expiry'));
  39. }
  40.  
  41. return true;
  42. }
  43. }
  44. }
  45.  
  46. return false;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement