-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex2.php
More file actions
165 lines (133 loc) · 4.74 KB
/
index2.php
File metadata and controls
165 lines (133 loc) · 4.74 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
<?php
ob_start();
session_start();
include('db_conn.php');
// it will never let you open index(login) page if session is set
if ( isset($_SESSION['user'])!="" ) {
header("Location: home.php");
exit;
}
$nameError ="";
$passError ="";
$emailError="";
$error = false;
if( isset($_POST['btn-sign-in']) ) {
// prevent sql injections/ clear user invalid inputs
$name = trim($_POST['name']);
$name = strip_tags($name);
$name = htmlspecialchars($name);
$pass = trim($_POST['pass']);
$pass = strip_tags($pass);
$pass = htmlspecialchars($pass);
// $pass =md5($pass);
// prevent sql injections / clear user invalid inputs
if(empty($name)){
$error = true;
$nameError = "Please enter your name.";
}
if(empty($pass)){
$error = true;
$passError = "Please enter your password.";
}
// if there's no error, continue to login
if (!$error) {
// password hashing using SHA256
$res="SELECT * FROM login WHERE username='$name' and password='$pass'";
$result=mysql_query($res);
$count = mysql_num_rows($result); // if uname/pass correct it returns must be 1 row
if( $count == 1 ) {
while($row=mysql_fetch_array($result))
{
$_SESSION['user'] = $row['username'];
header("Location:home.php");
}
} else {
$errMSG = "Incorrect Credentials, Try again...";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<title>Sign In</title>
<!-- Favicon-->
<link rel="icon" href="../../favicon.ico" type="image/x-icon">
<!-- Google Fonts -->
<link href="plugins/iconfont/material-icons.css" rel="stylesheet" type="text/css">
<!-- Bootstrap Core Css -->
<link href="plugins/bootstrap/css/bootstrap.css" rel="stylesheet">
<!-- Waves Effect Css -->
<link href="plugins/node-waves/waves.css" rel="stylesheet" />
<!-- Animation Css -->
<link href="plugins/animate-css/animate.css" rel="stylesheet" />
<!-- Custom Css -->
<link href="css/style.css" rel="stylesheet">
</head>
<body class="login-page">
<div class="login-box">
<div class="logo">
<b>LMS</b>
</div>
<?php
if ( isset($errMSG) ) {
?>
<?php echo $errMSG; ?>
<?php
}
?>
<div class="card">
<div class="body">
<form id="sign_in" method="POST" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" autocomplete="off">
<div class="msg">Sign in</div>
<div class="input-group">
<span class="input-group-addon">
<i class="material-icons">person</i>
</span>
<div class="form-line">
<input type="text" class="form-control" name="name" placeholder="Username" required autofocus>
<?php echo $nameError; ?>
</div>
</div>
<div class="input-group">
<span class="input-group-addon">
<i class="material-icons">lock</i>
</span>
<div class="form-line">
<input type="password" class="form-control" name="pass" placeholder="Password" required>
<?php echo $passError; ?>
</div>
</div>
<div class="row">
<div class="col-xs-4">
<button class="btn btn-block bg-pink waves-effect" type="submit" name="btn-sign-in">SIGN IN</button>
</div>
</div>
<div class="row m-t-15 m-b--20">
<div class="col-xs-6">
<a href="#">Register Now!</a>
</div>
<div class="col-xs-6 align-right">
<a href="#">Forgot Password?</a>
</div>
</div>
</form>
</div>
</div>
</div>
<!-- Jquery Core Js -->
<script src="plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap Core Js -->
<script src="plugins/bootstrap/js/bootstrap.js"></script>
<!-- Waves Effect Plugin Js -->
<script src="plugins/node-waves/waves.js"></script>
<!-- Validation Plugin Js -->
<script src="plugins/jquery-validation/jquery.validate.js"></script>
<!-- Custom Js -->
<script src="js/admin.js"></script>
<script src="js/pages/examples/sign-in.js"></script>
</body>
</html>
<?php ob_end_flush(); ?>