Guest User

Untitled

a guest
Nov 26th, 2018
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. public function login($username = NULL, $password = NULL, $remember = FALSE)
  2. {
  3. if(!$username && !$password && $this->exists())
  4. {
  5. Session::put($this->_sessionName, $this->data()->id);
  6. }
  7. else
  8. {
  9. $user = $this->find($username);
  10.  
  11. if($user)
  12. {
  13. if($this->data()->password === Hash::make($password, $this->data()->salt))
  14. {
  15. Session::put($this->_sessionName, $this->data()->id);
  16.  
  17. if($remember)
  18. {
  19. $hash = Hash::unique();
  20. $hashCheck = $this->_db->get('users_session',array('user_id','=',$this->data()->id));
  21.  
  22. if(!$hashCheck->count())
  23. {
  24. $this->_db->insert('users_session', array(
  25. 'user_id' => $this->data()->id,
  26. 'hash' => $hash
  27. ));
  28. }
  29. else
  30. {
  31. $hash = $hashCheck->first()->hash;
  32. }
  33.  
  34. Cookie::put($this->_cookieName, $hash, Config::get('remember/cookie_expiry'));
  35. }
  36. return true;
  37. }
  38. }
  39. }
  40.  
  41. return false;
  42. }
  43.  
  44. if(Input::exists())
  45. {
  46. if(Token::check(Input::get('token')))
  47. {
  48. $validation = new Validate();
  49. $validation = $validation->check($_POST, array(
  50. 'username' => array('required' => true),
  51. 'password' => array('required' => true)
  52. ));
  53. if($validation->passed())
  54. {
  55. $user = new User();
  56.  
  57. $remember = (Input::get('remember') === 'on') ? true : false;
  58. $login = $user->login(Input::get('username'), Input::get('password'), $remember);
  59.  
  60. if($login)
  61. {
  62. Redirect::to('user.php?user='.Input::get("username").'');
  63. }
  64. else
  65. {
  66. echo '<p>Sorry! Logging in failed</p>';
  67. }
  68. }
  69. else
  70. {
  71. foreach($validation->errors() as $error)
  72. {
  73. echo $error, '</br>';
  74. }
  75. }
  76. }
  77. }
Add Comment
Please, Sign In to add comment