Advertisement
Guest User

Untitled

a guest
Apr 8th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.35 KB | None | 0 0
  1. <?php
  2. //Database connectie
  3. include_once('../database/connection.php');
  4.  
  5. //Login class
  6. class user
  7. {
  8.  
  9.     private $db;
  10.  
  11.     //Database connection construct to use in the Login function
  12.     public function __construct()
  13.     {
  14.         $this->db = new Connection();
  15.         $this->db = $this->db->dbConnect();
  16.     }
  17.  
  18.     //Inlog function || Checking if there is a user and pass combination is in the database
  19.     //Password hashing
  20.     public function Login($name, $pass)
  21.     {
  22.         if (!empty($name) && !empty($pass)) {
  23.             $st = $this->db->prepare("select * from users where username=? and password=?");
  24.             $st->bindParam(1, $name);
  25.             $st->bindParam(2, $pass);
  26.             $st->execute();
  27.  
  28.             //Check if there is a combination with rowCount()
  29.             // "else" it gives you an error.
  30.             //
  31.             if ($st->rowCount() == 1) {
  32.                 //Session starter
  33.                 $_SESSION['login_user'] = $name;
  34.                 //If there is a combination you redirect to the index.
  35.                 header('Location: index.php');
  36.                 exit();
  37.  
  38.             } else
  39.             {
  40.                 echo "Incorrect Username or Password";
  41.             }
  42.  
  43.             } else
  44.             {
  45.                 echo "Please enter username and password";
  46.             }
  47.         }
  48. }
  49.  
  50. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement