-
Notifications
You must be signed in to change notification settings - Fork 1
/
admin.php
117 lines (105 loc) · 4.37 KB
/
admin.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
include_once 'config/db_connect.php';
$username = $password = '';
$error = ['username' => '', 'password' => '', 'error' => ''];
$noError = array('noError' => '');
if (isset($_POST['submit'])) {
if (empty($_POST['username'])) {
$error['username'] = 'Provide Username';
} else {
$username = trim($_POST['username']);
}
if (empty($_POST['password'])) {
$error['password'] = 'Provide your Password';
} else {
$password = trim($_POST['password']);
}
if (array_filter($error)) {
} else {
function fetchUsers($conn, $username, $password)
{
$sql = 'SELECT * FROM adminsystem WHERE AdminName = ?';
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
$error['error'] = 'Login Failed';
}
mysqli_stmt_bind_param($stmt, 's', $username);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$row = mysqli_fetch_assoc($result);
if ($row) {
$pwdHashed = $row['AdminPassword'];
$checkedPwd = password_verify($password, $pwdHashed);
if ($username === $row['AdminName'] && $checkedPwd === true) {
session_start();
$_SESSION['adminName'] = $row['AdminName'];
$_SESSION['adminId'] = $row['AdminID'];
return true;
}
if (!$username === $row['AdminName'] && $checkedPwd === false) {
return false;
}
if (!$username === $row['AdminName']) {
return false;
}
if ($checkedPwd === false) {
return false;
}
}
}
if (fetchUsers($conn, $username, $password) === true) {
header('Location: adminHome.php');
} elseif (fetchUsers($conn, $username, $password) !== true) {
$error['error'] = 'Login Failed Check if Username or Password Is correct';
} else {
$noError['noError'] = 'Login Successful';
}
}
}
?>
<?php include 'templates/header.php' ?>
<div class="container mt-6">
<div class="row align-items-center justify-content-around">
<div class="col-lg-4 text-center d-none d-lg-block">
<div class="display-4">
<span class="text-primary">Wyte</span>Mecury Admin
</div>
<p class="lead">Booking AnyMinutes, Time and Place</p>
</div>
<div class="col-lg-5 col-md-12 col-sm-12">
<div class="display-1 d-lg-none mb-2 text-center">
<span class="text-primary">We</span>Tic
</div>
<div <?php if ($error['username'] && $error['password']) : ?>>
<div class="alert alert-danger">
<?php echo 'Provide Both Username and Password' ?>
</div>
</div>
<div <?php elseif ($error['username']) : ?>>
<div class="alert alert-danger">
<?php echo $error['username']; ?>
</div>
</div>
<div <?php elseif ($error['password']) : ?>>
<div class="alert alert-danger">
<?php echo $error['password'] ?>
</div>
</div>
<div <?php elseif ($error['error']) : ?>>
<div class="alert alert-danger">
<?php echo $error['error'] ?>
</div>
<div <?php elseif ($noError['noError']) : ?>>
<div class="alert alert-success">
<?php echo $noError['noError'] ?>
</div>
</div <?php endif; ?>>
<form action="admin.php" method="POST">
<input type="text" name="username" class="form-control mb-3 form-control-lg" placeholder="Your Username" value='<?php echo $username; ?>'>
<input type="password" name="password" class="form-control mb-3 form-control-lg" placeholder="Your Password" value="<?php echo $password; ?>">
<input type="submit" name="submit" value="Login Admin" class="btn btn-secondary btn-lg col-12">
</form>
</div>
</div>
</div>
<?php include 'templates/footer.php' ?>