-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
93 lines (74 loc) · 2.68 KB
/
login.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
include 'connect.php';
$showEmpty = false;
$showError = false;
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST["username"];
$password = $_POST["password"];
if (empty($username) || empty($password)) {
$showEmpty = "Do Not Leave Required fields Empty";
}
$sql = "SELECT * FROM `teachers` WHERE `username`='$username'";
$result = mysqli_query($conn, $sql);
$num = mysqli_num_rows($result);
if ($num == 1) {
while ($row = mysqli_fetch_assoc($result)) {
if (password_verify($password, $row['password'])) {
session_start();
$_SESSION['loggedin'] = true;
$_SESSION['username'] = $username;
$_SESSION['teacherOf'] = $row['teacherOf'];
header("location: dashboard.php");
} else {
$showError = "Incorrect Password. Enter password again correctly or check your Username again";
}
}
} else {
$showError = "No Username Available. Please check again";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="Styling/header.css">
<link rel="stylesheet" href="Styling/style.css">
<link rel="stylesheet" href="Styling/login.css">
<link rel="stylesheet" href="Styling/alertBox.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<title>Login</title>
</head>
<body>
<?php session_start(); include("partials/_header.php"); ?>
<?php
if ($showError) {
echo
"<div class='error'>
<!-- <span class='closebtn'>×</span> -->
<strong>Error! </strong>" . $showError . "
</div>";
}
if ($showEmpty) {
echo
"<div class='empty'>
<!-- <span class='closebtn'>×</span> -->
<strong>Alert! </strong>" . $showEmpty . "
</div>";
}
?>
<div class="login-box" align="center">
<div class="login-container">
<h1>Login</h1>
<form action="login.php" method="POST">
<input type="text" name="username" id="inputForm" placeholder="Username" required><br>
<input type="password" name="password" id="inputForm" placeholder="Password" required><br>
<button id="login-button" type="submit">Login</button>
</form>
<sub><a class="link" href="index.php">Visit Home page if you are student</a></sub>
</div>
</div>
</body>
</html>