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($_POST[$username]) && isset($_POST[$password])) {
- $username = $_POST[$username];
- $password = password_hash($_POST[$password], PASSWORD_BCRYPT);
- if (empty($username) || empty($password)) {
- $this->errors = 'Wrong details';
- } else {
- require_once('Database.php');
- $db = new Database();
- $query = $db->connection->prepare(" SELECT * FROM users WHERE username='$username' LIMIT 1 ");
- $query->execute(array($username));
- if ($query->rowCount() == 1) {
- $this->result = $query->fetch(PDO::FETCH_OBJ);
- $this->db_pass = $this->result->password;
- $this->id = $this->result->id;
- }
- if (password_verify($password, $this->db_pass)) {
- $_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