-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
272 lines (233 loc) · 9.66 KB
/
index.php
File metadata and controls
272 lines (233 loc) · 9.66 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<?php
session_start();
$Error="";
if(isset($_COOKIE['studreg'])){
header("location:StudentView.php");
}
if(isset($_SESSION['spiusername'])){
header("location:view.php");
}
if($_SERVER["REQUEST_METHOD"] == "POST") {
// username and password sent from form
//if session not working at new device set session only once $_SESSION['spiusername'] = "afdr" and destroy it $_SESSION['spiusername'] = "";
if(isset($_POST['username'])){
$user =$_POST['username'];
$pass =$_POST['password'];
$pass=MD5(trim($pass));
}else{
$user =" ";
$pass =" ";
}
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "spi";
// Create connection
$conn = new mysqli($servername, $username, $password,$dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT username,password FROM Staff";
$result = $conn->query($sql);
if ($result==true && $result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()){
if($row["username"]==$user){
if($row["password"]==$pass){
if(!isset($_SESSION['spiusername'])){
$_SESSION['spiusername'] = $user;
$_SESSION['spipassword'] = $pass;
}
$conn->close();
exit(header("location:view.php"));
}//p if
else{
$Error="Username/Password may be incorrect";
}
}//u if
else{
$Error="Username / Password may be incorrect";
}if(isset($_SESSION['spipassword'])){
if($_SESSION['spipassword']!==$row["username"]){
$ses=True;
}}
}//wh
if(isset($ses) && $ses==True){
echo $_SESSION['spiusername'].
"<h2><a href = \"logout.php\">Please Sign Out</a></h2>";
}
}//res
$conn->close();
}//post if
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>SPI Login</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--===============================================================================================-->
<link rel="icon" type="image/png" href="images/icons/favicon.ico"/>
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/bootstrap/css/bootstrap.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/fonts/font-awesome-4.7.0/css/font-awesome.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/fonts/iconic/css/material-design-iconic-font.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/main.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/login.css">
</head>
<body>
<img class="wave" src="images/wave.png">
<div class="container">
<div class="img">
<img src="images/bg.png">
</div>
<!-- <img src="images/avatar.svg"> -->
<div class="container-login100" style="">
<div class="wrap-login100 p-l-55 p-r-55 p-t-80 p-b-30">
<ul id="nv" class="nav nav-tabs bg-transparent justify-content-center" role="tablist">
<li class="nav-item">
<a id="lgn1" class="nav-link" data-toggle="tab" href="#S-login">S-Login</a>
</li>
<li class="nav-item">
<a id="lgn2" class="nav-link" data-toggle="tab" href="#T-login">T-Login</a>
</li>
<li class="nav-item">
<a id="lgn3" class="nav-link" data-toggle="tab" href="#C-user">Sign Up</a></li>
</ul>
<span class="tab-content">
<div id="S-login" class="container tab-pane fade" style="word-break: break-all;">
<img id="avatar" src="images/avatar.png">
<span class="login100-form-title p-b-37"> Student's Login</span>
<form id="form1" class="login100-form validate-form" method="POST" action="<?php echo htmlentities('student_verification.php'); ?>" >
<div class="wrap-input100 validate-input m-b-20" data-validate="Enter Name">
<input class="input100" type="text" name="studname" placeholder="Name">
<span class="focus-input100"></span>
</div>
<div class="wrap-input100 validate-input m-b-25" data-validate = "Enter RegisterNumber">
<input class="input100" type="number" name="studreg" placeholder="RegisterNumber">
<span class="focus-input100"></span>
</div>
<div class="container-login100-form-btn">
<button id="slogin" type="submit" value="submit" class="login100-form-btn">
Login
</button>
</div>
</form>
<div class="container-login100-form-btn ">
<p id="err"></p>
</div>
</div>
<div id="T-login" class="container tab-pane fade" style="word-break: break-all;">
<img id="avatar" src="images/avatar.png">
<span class="login100-form-title p-b-37"> Teacher's Login</span>
<form id="form2" class="login100-form validate-form1" method="POST" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" >
<div class="wrap-input100 validate-input1 m-b-20" data-validate="Enter Username ">
<input class="input100" type="text" name="username" placeholder="Username">
<span class="focus-input100"></span>
</div>
<div class="wrap-input100 validate-input1 m-b-25" data-validate = "Enter Password">
<input class="input100" type="password" name="password" placeholder="Password">
<span class="focus-input100"></span>
</div>
<div class="container-login100-form-btn">
<button id="tlogin" type="submit" value="submit" class="login100-form-btn">
Login
</button>
</div>
</form>
<div class="container-login100-form-btn ">
<p><?php echo $Error; ?></p>
</div>
</div>
<div id="C-user" class="container tab-pane fade" style="word-break: break-all;">
<span class="login100-form-title p-b-37">Create User</span>
<form id="form3" class="login100-form validate-form2" method="POST">
<div class="wrap-input100 validate-input2 m-b-20" data-validate="Enter Username ">
<input class="input100" type="text" name="CreateUser" placeholder="Username">
<span class="focus-input100"></span>
</div>
<div class="wrap-input100 validate-input2 m-b-25" data-validate = "Enter Password">
<input class="input100" type="password" name="CreatePass" placeholder="Password">
<span class="focus-input100"></span> </div>
<div class="wrap-input100 validate-input2 m-b-20" >
<input class="input100" type="text" name="cc" placeholder="Your class as a CC "><span class="focus-input100"></span> </div> <small class="form-text text-muted"> Example:2017-2021-CSE-A</small>
<div class="wrap-input100 validate-input2 m-b-20" >
<input class="input100" type="text" name="class1" placeholder="Your class as a mentor ">
<span class="focus-input100"></span>
</div>
<div class="wrap-input100 validate-input2 m-b-25" >
<input class="input100" type="password" name="unqid" placeholder="Unique Password">
<span class="focus-input100"></span>
</div>
<div class="container-login100-form-btn">
<button id="create" type="submit" value="submit" class="login100-form-btn cr-al" style="float:left">
Sign Up
</button>
<button id="alter" type="submit" value="submit" class="login100-social-item cr-al" style="float:right">Alter</button>
</div>
</form>
<div class="container-login100-form-btn ">
<p id="error"></p>
</div>
</div>
</span>
</div>
</div>
<!--===============================================================================================-->
<script src="vendor/jquery/jquery-3.2.1.min.js"></script>
<!--===============================================================================================-->
<script src="vendor/bootstrap/js/popper.js"></script>
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<!--===============================================================================================-->
<script src="vendor/main.js"></script>
<script>
$(document).ready(function() {
var i=0;
$(".cr-al").click(function(e){
e.preventDefault();
console.log("clicked");
var user =$('[name=CreateUser]').val();
var pass =$('[name=CreatePass]').val();
var id =$('[name=unqid]').val();
if (user.length>5 && pass.length>5 && id.length==12){
var cc =$('[name=cc]').val();
var class1 =$('[name=class1]').val();
var si =$(this).attr("id");
$.ajax({
type: "POST",
url: 'register_backend.php',
data:{spiuser:user,spipass:pass,cc:cc,class1:class1,unqid:id,a:si},
success: function(data){
if (data !=="") {
$("#error").html(data);
i++;
if(i>2){
window.location="index.php";
}
}
if (data =="") {
//header location
$("#lgn2").trigger("click");
$("input").val("");
alert("Successfully Created");
}
}//suc
});//aj
}//if
});//clk
//if active class is added on tabs trigger doesnt work on tabs
$("#lgn2").trigger("click");
});//doc
</script>
</body>
</html>