This repository has been archived by the owner on May 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
69 lines (65 loc) · 2.68 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?PHP
session_start();
/*Check to see if already logged in*/
if(!isset($_SESSION["username"])){
/*Are they trying to login?*/
if(isset($_REQUEST['username'])){
require_once 'lib/password.php';
require_once 'scripts/makedbconnection.php';
$connection = makeDBConnection(DB_HOST, DB_ADMIN, DB_ADMIN_PASSWORD, DB_NAME);
$username = filter_var($_REQUEST['username']);
$password = filter_var($_REQUEST['password']);
$sql = "select role, password from users where username='$username';";
$result = $connection->query($sql);
$validate = $result->fetch_assoc();
/*Success*/
if (password_verify($password, $validate["password"])){
$_SESSION["username"] = $username;
$_SESSION["role"] = $validate["role"];
header('Location: ./homepage.php');
exit();
}
/*Failed to login. Sets the warning then loads the rest of the page*/
else {
$errormessage = "Invalid Credentials";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Login</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="css/mainstyle.css" type="text/css">
<link rel="stylesheet" href="font-awesome/css/font-awesome.min.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-lg-3"></div>
<div class='col-lg-6'>
<?PHP echo (isset($errormessage)? "<h1 id='error'>$errormessage</h1>" : ""); ?>
<?PHP echo (isset($_GET["logout"]) ? "<h1>You have been logged out</h1>" : ""); ?>
<form action='<?PHP echo $_SERVER['PHP_SELF']; ?>' method='post'>
<h2>Software Tracker</h2>
<div class='form-group'>
<input class="form-control" type="text" name="username" placeholder='Username' value="<?PHP echo (isset($_REQUEST["username"]) ? $_REQUEST["username"] : "");?>" required>
<input class="form-control" type='password' name='password' placeholder='Password'>
</div>
<button class="btn btn-default" type='submit'>Log In</button>
</form>
</div>
<div class="col-lg-3"></div>
</div>
</div>
</body>
</html>
<?PHP
/*If they were logged in*/
}
else {
header('Location: ./homepage.php');
exit();
}
?>