-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
76 lines (72 loc) · 2.73 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
<?php
session_start();
$errorMsg = "";
//Get the xml
$loginXML = simplexml_load_file("xml/login.xml");
if(isset($_SESSION['userid']) && isset($_SESSION['user'])){
header('Location: ticketlist.php');
}
//Checking login indentifications from the xml
if(isset($_POST['login'])){
foreach($loginXML as $user){
//echo md5($_POST['password']);
$username = $_POST['username'];
$password = $_POST['password'];
//Checking if the username input matches the XML element -&-
//Checking if the password input matches the XML MD5 encrypted element.
if($username == $user->username && md5($password) == $user->password->encrypted){
//Storing both the username and userid as strings.
$_SESSION['user'] = (string) $user->username;
$_SESSION['userid'] = (string) $user->userId;
//Once validated redirect the user to the 'ticketlist.php' page.
header('Location: ticketlist.php');
exit;
}
elseif(empty($username)){
$errorMsg = "username must not be empty!";
}
elseif(empty($password)){
$errorMsg = "password must not be empty!";
}
else {
$errorMsg = "this username or password doesn't exist";
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<?php include 'views/head.php'?>
<body data-theme="">
<div class="dark-mode">
<input type="checkbox" name="" id="btn"/>
<div class="mode-box">
<i class="fa fa-adjust"></i>
<i class="fa fa-adjust"></i>
</div>
</div>
<div class="top">
<div class="top-wave"></div>
<div class="seperate">
<h1 class="color"><i class="fa fa-comments"></i> Support Ticket Sytem</h1>
</div>
</div>
<div class="page__container">
<div class=" centerContent">
<form action="" method="POST" class="add-form">
<div>
<input type="text" name="username" placeholder="username"
value="<?= isset($_POST['username'])? $_POST['username']: '';?>"/>
<input type="password" name="password" placeholder="password"
value="<?= isset($_POST['username'])? $_POST['password']: '';?>"/>
<input type="submit" name="login" class="correct__btn" value="Login">
<br/>
<span class="errors__mandate"><?=$errorMsg?></span>
</div>
</form>
<a href="addUser.php" class="correct__btn">Create A New User</a>
</div>
</div>
</body>
<?php include 'views/footer.php'?>
</html>