Skip to content
Permalink
ebd8885abc
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
132 lines (108 sloc) 4.63 KB
<?php
// Start the session
session_start();
if(isset($_COOKIE["PHPSESSID"])){
header('Set-Cookie: PHPSESSID='.$_COOKIE["PHPSESSID"].'; SameSite=Lax');
}
?>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link href="/bootstrap.min.css" rel="stylesheet">
<title>Learn Hacking (Again)!</title>
</head>
<body>
<div class="container">
<header class="p-3 mb-3 border-bottom" style="background-color: #e3f2fd;">
<div class="container">
<div class="d-flex flex-wrap align-items-center justify-content-center justify-content-lg-start">
<a href="/" class="d-flex align-items-center mb-2 mb-lg-0 text-dark text-decoration-none">
<img class="bi me-2" width="40" height="32" role="img" aria-label="Bootstrap" src="/images/HoodieHacker.svg"/>
</a>
<ul class="nav col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0">
<li><a href="/" class="nav-link px-2 link-dark">Overview</a></li>
<li><a href="/topics.php" class="nav-link px-2 link-secondary">Topics</a></li>
<li><a href="/enquire.php" class="nav-link px-2 link-dark">Enquiries</a></li>
<?php
if (isset($_SESSION["userid"])){
echo '<li><a href="/profile.php" class="nav-link px-2 link-dark">Profile</a></li>';
echo '<li><a href="/logout.php" class="nav-link px-2 link-dark">Logout</a></li>';
}
else{
echo '<li><a href="/login.php" class="nav-link px-2 link-dark">Login</a></li>';
}
?>
</ul>
<form class="col-12 col-lg-auto mb-3 mb-lg-0 me-lg-3">
<input type="search" class="form-control" placeholder="Search..." aria-label="Search">
</form>
</div>
</div>
</header>
<div class="row">
<div class="col-8">
<form class="form-signin" method="post">
<h1 class="h3 mb-3 font-weight-normal">Please sign in</h1>
<label for="inputEmail" class="sr-only">uusername</label>
<input type="email" id="inputEmail" name="email" class="form-control" placeholder="email" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" id="inputPassword" name="password" class="form-control" placeholder="Password" required>
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>
</div>
</div>
<!-- Code at https://github.coventry.ac.uk/CUEH/Learn_Hacking_Web -->
<?php
require("conn.php");
//Login Throttle
$date = new DateTime();
$ts = $date->getTimestamp();
$control = $db->querySingle('SELECT * from loginControl WHERE id=1', true);
$timeTaken = $ts-$control["last"];
if ($control["sleepTill"] - $ts > 0){
http_response_code(403);
$timeLeft = $control["sleepTill"]-$ts;
die("<div class='alert alert-warning'>Too Many Requests: Sleeping for {$timeLeft}</div>");
}
$theCount = $control["count"];
if ($theCount > 15){
$sleepyTime = $ts+5;
$qryString = "UPDATE loginControl SET count = 0, last = {$ts}, sleepTill={$sleepyTime} WHERE id = 1";
$db->querySingle($qryString);
$theCount = 0;
}
//Login Logic
$email = $_POST["email"];
$password = $_POST["password"];
$hash = md5($password);
if (isset($email)) {
$newCount = $theCount + 1;
$qryString = "UPDATE loginControl SET count = {$newCount}, last = {$ts} WHERE id = 1";
$db->querySingle($qryString);
$qry = "SELECT * FROM users WHERE email='{$email}'";
$result = $db->query($qry);
$row = $result->fetchArray();
if ($row){
if (strcmp($hash, $row['password']) !== 0 ){
echo "<div class='alert alert-info'>Incorrect Password for ${row['email']}</div>";
}
else {
echo "<div class='alert alert-success'>Login Correct</div>";
$_SESSION["userid"] = $row["id"];
$_SESSION["email"] = $row["email"];
$_SESSION["name"] = $row["name"];
}
}
else {
echo "<div class='alert alert-info'>No Such User</div>";
}
}
?>
</div>
</body>
</html>