Advertisement
Guest User

Untitled

a guest
Apr 7th, 2016
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 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($username) && isset($password)) {
  13.             if (empty($username) || empty($password)) {
  14.                 $this->errors = 'Wrong details';
  15.             } else {
  16.                 require_once('Database.php');
  17.                 $db = new Database();
  18.  
  19.                 $query = $db->prepare(" SELECT * FROM users WHERE username = :username LIMIT 1 ");
  20.                 $query->execute([':username' => $username]);
  21.                 $fetchHash = $db->fetch(PDO::FETCH_ASSOC);
  22.  
  23.                 if ($query->rowCount()) {
  24.                     $this->result = $query->fetch(PDO::FETCH_OBJ);
  25.                     $this->db_pass = $this->result->password;
  26.                     $this->id = $this->result->id;
  27.                 }
  28.                 if (password_verify($password, $fetchHash['HASH COLUMN NAME HERE'])) {
  29.                     $_SESSION['username'] = $username;
  30.                     $_SESSION['id'] = $this->id;
  31.                     header('location:index.php');
  32.                 }
  33.             }
  34.         }
  35.     } // END OF FUNCTION
  36. } // END OF CLASS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement