Advertisement
Guest User

Untitled

a guest
May 14th, 2016
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. public function login($username, $password){
  2. $this->db->query("SELECT * FROM users WHERE username = :username AND status = :status LIMIT 1");
  3. $this->db->bind(':username', $username);
  4. $this->db->bind(':status', 1);
  5. $row = $this->db->single();
  6. $count = $this->db->rowCount();
  7. if ($count > 0) {
  8. if (password_verify($password, $row['password'])) {
  9. $_SESSION['session'] = [
  10. 'id' => $row['id'],
  11. 'username' => $row['username'],
  12. 'email' => $row['email'],
  13. ];
  14. return true;
  15. } else {
  16. return false;
  17. }
  18. }
  19. }
  20.  
  21. public function isLoggedIn() {
  22. if (isset($_SESSION['session'])) {
  23. return true;
  24. }
  25. }
  26.  
  27. if ($user->isLoggedIn()) {
  28. header('Location: index.php');
  29. exit();
  30. }
  31.  
  32. if(isset($_POST['login'])){
  33.  
  34. //Retrieve the field values from our login form.
  35. $username = !empty($_POST['username']) ? trim($_POST['username']) : null;
  36. $password = !empty($_POST['password']) ? trim($_POST['password']) : null;
  37.  
  38. if($user->login($username, $password)) {
  39. header('Location: index.php');
  40. exit();
  41. } else {
  42. $message[] = 'We found problems with the login, please try again.';
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement