Advertisement
Guest User

Untitled

a guest
Apr 7th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. <?php
  2. session_start();
  3. class User
  4. {
  5. public $errors;
  6. public $result;
  7. public $id;
  8. public $db_pass;
  9.  
  10. public function logIn($username, $password)
  11. {
  12. if (isset($_POST[$username]) && isset($_POST[$password])) {
  13.  
  14. $username = $_POST[$username];
  15. $password = password_hash($_POST[$password], PASSWORD_BCRYPT);
  16.  
  17. if (empty($username) || empty($password)) {
  18. $this->errors = 'Wrong details';
  19. } else {
  20. require_once('Database.php');
  21. $db = new Database();
  22. $query = $db->connection->prepare(" SELECT * FROM users WHERE username='$username' LIMIT 1 ");
  23. $query->execute(array($username));
  24.  
  25. if ($query->rowCount() == 1) {
  26. $this->result = $query->fetch(PDO::FETCH_OBJ);
  27. $this->db_pass = $this->result->password;
  28. $this->id = $this->result->id;
  29. }
  30. if (password_verify($password, $this->db_pass)) {
  31. $_SESSION['username'] = $username;
  32. $_SESSION['id'] = $this->id;
  33. header('location:index.php');
  34. }
  35. }
  36. }
  37. } // END OF FUNCTION
  38. } // END OF CLASS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement