-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
72 lines (67 loc) · 2.56 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
<?php
include("dbconfig.php");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST") {
foreach($_POST as $key=>$value) {
if(empty($_POST[$key])) {
$message = "<div class=\"alert alert-danger\">" . ucwords($key) . " field is required!</div>";
break;
}
}
if (!isset($message)) {
$user_email = mysqli_real_escape_string($conn, $_POST['email']);
$password = mysqli_real_escape_string($conn, $_POST['password']);
$sql = "SELECT * FROM account WHERE email_address = '$user_email'";
$result = mysqli_query($conn, $sql);
$count = mysqli_num_rows($result);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
$hashed_password = $row['password'];
// If result matched $myusername and $mypassword, table row must be 1 row
if( password_verify($password, $hashed_password) && $count == 1) {
$_SESSION['login_user'] = $user_email;
if ($row['isAdmin'] == 1)
header("location:admin_welcome.php");
else
header("location: welcome.php");
} else {
$message = "<div class=\"alert alert-danger\">Your Login Name or Password is invalid!</div>";
}
}
}
$conn->close();
?>
<html>
<head>
<?php require_once('head.php'); ?>
<title>Login Page</title>
</head>
<body>
<div class="container">
<div class="jumbotron">
<h1>Assignment Book</h1>
<p>welcome to assignment book!</p>
</div>
</div>
<div class="container">
<div class="col-md-4">
<form action = "" method = "post">
<h1 class= "form-signin-heading">Login</h1>
<label>Email :</label><input type="text" name="email" class="form-control"><br/>
<label>Password :</label><input type="password" name="password" class="form-control"><br/>
<div class="btn-group btn-group-justified" role="group">
<div class="btn-group" role="group">
<input class="btn btn-primary" type = "submit" value = "Submit"/>
</div>
<div class="btn-group" role="group">
<a href="register.php" class="btn btn-primary" role="button">Register</a>
</div>
</div>
<br/>
<a href="index.php" class="btn btn-primary" role="button">Back to Homepage</a>
</form>
<div><?php if (isset($message)) echo $message; ?></div>
</div>
</div>
<?php require_once('common_footer.html'); ?>
</body>
</html>