-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.php
67 lines (63 loc) · 2.33 KB
/
auth.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
<?php
session_start();
include("config.php");
$connection = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
if (!$connection) {
echo "kle vaata oma db üle, armas inimene, eks";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Authenticate yourself \\ REDDIT</title>
<meta name="author" content="Kaspar Kivistik">
<meta http-equiv="X-UA-Compatible" content="IE-edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://bootswatch.com/3/simplex/bootstrap.min.css"/>
<link rel="stylesheet" href="stylesheet.css">
</head>
<?php
include("header.php");
?>
<body class="centered-wrapper">
<form class="centered-content form-horizontal" method="post">
<fieldset>
<legend>log in to this WONDERFUL site</legend>
<div class="form-group">
<label class="col-lg-2 control-label">Username</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="username" placeholder="Username" required>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">Password</label>
<div class="col-lg-10">
<input type="password" class="form-control" name="password" placeholder="Password" required>
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<input type="submit" class="btn btn-primary"/>
</div>
</div>
</fieldset>
<?php
if (isset($_REQUEST['username']) and isset($_REQUEST['password'])) {
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$password = hash('sha512', $password);
$query = "SELECT * FROM 164347_users WHERE user_name = '$username' AND password = '$password'";
if (count(mysqli_fetch_array(mysqli_query($connection, $query)))) {
$_SESSION['username'] = $username;
$message = "successfully logged in";
echo "<script type='text/javascript'>alert('$message');</script>";
header("Location: index.php");
} else {
echo "<script type='text/javascript'>alert(\"invalid username or password\");</script>";
}
}
?>
</form>
</body>
</html>