-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
181 lines (154 loc) · 5.59 KB
/
Copy pathindex.php
File metadata and controls
181 lines (154 loc) · 5.59 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
<?php
session_start();
if (!empty($_SESSION['role']) && ($_SESSION['role'] == 'User')) {
header("Location: users/index.php");
exit();
}
require_once('db.php');
$show = 'hidden';
$msg = '';
if (isset($_POST['submit'])) {
$time = time() - 30;
$ip_address = getIpAddr();
// Getting total count of hits on the basis of IP
$query = mysqli_query($conn, "SELECT COUNT(*) AS total_count FROM loginlogs WHERE TryTime > $time AND IpAddress='$ip_address'");
$check_login_row = mysqli_fetch_assoc($query);
$total_count = $check_login_row['total_count'];
//Checking if the attempt 3, or youcan set the no of attempt her. For now we taking only 3 fail attempted
if ($total_count == 3) {
$msg = "To many failed login attempts. Please login after 30 sec";
} else {
//Getting Post Values
$email = $_POST['email'];
$password = $_POST['password'];
// Coding for login
$sql = "SELECT * FROM student_info WHERE user_email='$email' AND user_pass='$password'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$_SESSION['logged_in'] = 'yes';
$_SESSION['fullname'] = $row['firstname'] . ' ' . strtoupper(first_char($row['middlename'])) . '. ' . $row['lastname'] . ' ' . $row['allias'];
$_SESSION['status'] = $row['status'];
$_SESSION['id'] = $row['user_id'];
$_SESSION['role'] = 'User';
mysqli_query($conn, "DELETE FROM loginlogs WHERE IpAddress='$ip_address'");
$user_id = $row['user_id'];
$activity = 'Logged in as User (' . $row['firstname'] . ' ' . strtoupper(first_char($row['middlename'])) . '. ' . $row['lastname'] . ' ' . $row['allias'] . ')';
$audit = "INSERT INTO audit_trails (user_id, activity) VALUES ('$user_id', '$activity')";
$conn->query($audit);
header('location: users/index.php');
}
} else {
$total_count++;
$rem_attm = 3 - $total_count;
if ($rem_attm == 0) {
$show = '';
$msg = "To many failed login attempts. Please login after 30 sec";
} else {
$show = '';
$msg = "Please enter valid login details.<br/>$rem_attm attempts remaining<br/>";
}
$try_time = time();
mysqli_query($conn, "insert into loginlogs(IpAddress,TryTime) values('$ip_address','$try_time')");
}
}
}
// Getting IP Address
function getIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ipAddr = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ipAddr = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ipAddr = $_SERVER['REMOTE_ADDR'];
}
return $ipAddr;
}
function first_char($str)
{
if ($str)
return strtolower(substr($str, 0, 1));
return false;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Strand DSS | Log in</title>
<!-- Tell the browser to be responsive to screen width -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Font Awesome -->
<link rel="stylesheet" href="plugins/fontawesome-free/css/all.min.css">
<!-- Ionicons -->
<link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
<!-- icheck bootstrap -->
<link rel="stylesheet" href="plugins/icheck-bootstrap/icheck-bootstrap.min.css">
<!-- Theme style -->
<link rel="stylesheet" href="dist/css/adminlte.min.css">
<!-- Google Font: Source Sans Pro -->
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
</head>
<body class="hold-transition login-page">
<div class="login-box">
<div class="login-logo">
<a href="#"><b>Strand</b>DSS</a>
<a href="#">
<h5>Student Sign in</h5>
</a>
</div>
<!-- /.login-logo -->
<div class="card">
<div class="card-body login-card-body">
<p class="login-box-msg">Sign in to start your session</p>
<div <?php echo $show ?> class="callout callout-danger text-center" id="result">
<?php echo $msg ?>
</div>
<form id="login-form" method="post">
<div class="input-group mb-3">
<input type="email" name="email" class="form-control" placeholder="Email">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-envelope"></span>
</div>
</div>
</div>
<div class="input-group mb-3">
<input type="password" name="password" class="form-control" placeholder="Password">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-lock"></span>
</div>
</div>
</div>
<div class="row">
<div class="col-8">
<div class="icheck-primary">
<input type="checkbox" id="remember">
</div>
</div>
<!-- /.col -->
<div class="col-4">
<button type="submit" name="submit" class="btn btn-primary btn-block">Sign In</button>
</div>
<!-- /.col -->
</div>
</form>
<p class="mb-1">
<a href="register.php">Sign up here</a>
</p>
</div>
<!-- /.login-card-body -->
</div>
</div>
<!-- /.login-box -->
<!-- jQuery -->
<script src="plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/adminlte.min.js"></script>
</body>
</html>