Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Database connectie
- include_once('../database/connection.php');
- //Login class
- class user
- {
- private $db;
- //Database connection construct to use in the Login function
- public function __construct()
- {
- $this->db = new Connection();
- $this->db = $this->db->dbConnect();
- }
- //Inlog function || Checking if there is a user and pass combination is in the database
- //Password hashing
- public function Login($name, $pass)
- {
- if (!empty($name) && !empty($pass)) {
- $st = $this->db->prepare("select * from users where username=? and password=?");
- $st->bindParam(1, $name);
- $st->bindParam(2, $pass);
- $st->execute();
- //Check if there is a combination with rowCount()
- // "else" it gives you an error.
- //
- if ($st->rowCount() == 1) {
- //Session starter
- $_SESSION['login_user'] = $name;
- //If there is a combination you redirect to the index.
- header('Location: index.php');
- exit();
- } else
- {
- echo "Incorrect Username or Password";
- }
- } else
- {
- echo "Please enter username and password";
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement