Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- class User
- {
- public $errors;
- public $result;
- public $id;
- public $db_pass;
- public function logIn($username, $password)
- {
- if (isset($username) && isset($password)) {
- if (empty($username) || empty($password)) {
- $this->errors = 'Wrong details';
- } else {
- require_once('Database.php');
- $db = new Database();
- $query = $db->prepare(" SELECT * FROM users WHERE username = :username LIMIT 1 ");
- $query->execute([':username' => $username]);
- $fetchHash = $db->fetch(PDO::FETCH_ASSOC);
- if ($query->rowCount()) {
- $this->result = $query->fetch(PDO::FETCH_OBJ);
- $this->db_pass = $this->result->password;
- $this->id = $this->result->id;
- }
- if (password_verify($password, $fetchHash['HASH COLUMN NAME HERE'])) {
- $_SESSION['username'] = $username;
- $_SESSION['id'] = $this->id;
- header('location:index.php');
- }
- }
- }
- } // END OF FUNCTION
- } // END OF CLASS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement