Skip to content

Commit

Permalink
added login requirement to index. fixed paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mutate committed Mar 10, 2012
1 parent 484adf2 commit f9f83ca
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
8 changes: 8 additions & 0 deletions index.php
@@ -1,3 +1,11 @@
<?php
session_start();

if ($_SESSION['loggedIn'] != true)
header('location:forms/login.php');

?>

<html>
<head>
<title>BIT 285 Class Project: BIT561 Vision Statement and Test Menu</title>
Expand Down
22 changes: 22 additions & 0 deletions php/authorize.php
@@ -0,0 +1,22 @@
<?php

require_once ('checkUser.php');

$username = $_REQUEST['userName'];
$password = $_REQUEST['password'];

$newCheck = new CheckUser ($username, $password);

$result = $newCheck->authenticate();

if ($result == 1) {
session_start();
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
$_SESSION['loggedIn'] = true;
header("Location:../index.php");
} else {
echo 'Login Failed';
}

?>
30 changes: 30 additions & 0 deletions php/checkUser.php
@@ -0,0 +1,30 @@
<?php

class CheckUser {

private $username;
private $password;

function __construct($username, $password) {
$this->username = $username;
$this->password = $passwword;
}

function authenticate () {

require_once('DBManager.php');
require_once('db_login.php');

$db_dsn = "mysql:host={$db_host};dbname={$db_database}";

$DB = new DBManager($db_dsn, $db_username, $db_password);
$DB->open();

$loginQuery = "SELECT COUNT(*) FROM users WHERE userName = '" .$this->username. "' AND password = '" .$this->password. "'";
$getLogin = $DB->execute($loginQuery);


return $getLogin;
}
}
?>

0 comments on commit f9f83ca

Please sign in to comment.