-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreset.php
More file actions
198 lines (149 loc) · 6.31 KB
/
reset.php
File metadata and controls
198 lines (149 loc) · 6.31 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
<!DOCTYPE html>
<html lang="en">
<?php
include('header.php');
?>
<?php
//prevent user from coming to reset page if there is no email or token in url
if (!isset($_GET['email']) && !isset($_GET['token'])) {
redirect("index.php");
} else {
if (isset($_POST['reset_submit'])) {
//we have to make sure that the information we are receiving from the email belongs to the right user
$email = $_GET['email']; //from url
$token = $_GET['token']; //from url
$stmt = query("SELECT username,user_email,token FROM users WHERE token='{$token}'");
$row = $stmt->fetch(PDO::FETCH_ASSOC);
//check if the token and email from url match the correct user in database
if (($_GET['token'] !== $row['token']) && ($_GET['email'] !== $row['user_email'])) {
redirect("index.php");
}
$password = validate($_POST['password']);
$password_repeat = validate($_POST['password_repeat']);
$password_size = strlen($password);
//CHECKING FOR ERRORS
if (empty($password) || empty($password_repeat)) {
redirect("reset.php?error=emptyFields");
exit();
} elseif ($password_size <= 4) {
//check if length of password is valid
redirect("reset.php?error=invalid_pwd_length");
exit();
} elseif ($password !== $password_repeat) {
//check if password are same
redirect("reset.php?error=pwd_no_match");
exit();
}
//updating password and token columns
$passwordHash = password_hash($password, PASSWORD_DEFAULT);
$token_update = "Token used"; //once we are done using the token, we don't want it anymore
$stmt = prepare_query("UPDATE users SET user_password=?,token=? WHERE user_email=?");
$stmt->bindParam(1, $passwordHash, PDO::PARAM_STR);
$stmt->bindParam(2, $token_update, PDO::PARAM_STR);
$stmt->bindParam(3, $email, PDO::PARAM_STR);
$stmt->execute();
unset($stmt);
redirect("login.php?success=reset");
}
}
?>
<section class="ftco-section">
<div class="container">
<div class="row">
<div class="col-xl-10 ftco-animate">
<!-- Display error messages -->
<?php display_error_message(); ?>
<!-- Display success messages -->
<?php display_success_message(); ?>
<form action="" method="post" class="p-3 billing-form ftco-bg-dark p-md-5">
<h3 style="text-align:center" class="mb-4 billing-heading">Reset Password</h3>
<div class="col-md-12">
<div class="form-group">
<label for="password">New Password</label>
<input type="password" class="form-control" name="password" placeholder="Enter new password">
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label for="password">Repeat New Password</label>
<input type="password" class="form-control" name="password_repeat" placeholder="repeat new password">
</div>
</div>
<div class="row justify-content-center">
<div class="form-group">
<button type="submit" name="reset_submit" class="btn btn-primary btn-lg">LOG IN</button>
</div>
</div>
<br>
<input type="hidden" class="hide" name="token" id="token" value="">
</form>
</div>
</div>
</div>
</section>
<?php
include('footer.php');
?>
<div id="ftco-loader" class="show fullscreen"><svg class="circular" width="48px" height="48px">
<circle class="path-bg" cx="24" cy="24" r="22" fill="none" stroke-width="4" stroke="#eeeeee" />
<circle class="path" cx="24" cy="24" r="22" fill="none" stroke-width="4" stroke-miterlimit="10" stroke="#F96D00" />
</svg></div>
<script src="js/jquery.min.js"></script>
<script src="js/jquery-migrate-3.0.1.min.js"></script>
<script src="js/popper.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.easing.1.3.js"></script>
<script src="js/jquery.waypoints.min.js"></script>
<script src="js/jquery.stellar.min.js"></script>
<script src="js/owl.carousel.min.js"></script>
<script src="js/jquery.magnific-popup.min.js"></script>
<script src="js/aos.js"></script>
<script src="js/jquery.animateNumber.min.js"></script>
<script src="js/bootstrap-datepicker.js"></script>
<script src="js/jquery.timepicker.min.js"></script>
<script src="js/scrollax.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBVWaKrjvy3MaE7SQ74_uJiULgl1JY0H2s&sensor=false"></script>
<script src="js/google-map.js"></script>
<script src="js/main.js"></script>
<script>
$(document).ready(function() {
var quantitiy = 0;
$('.quantity-right-plus').click(function(e) {
// Stop acting like a button
e.preventDefault();
// Get the field name
var quantity = parseInt($('#quantity').val());
// If is not undefined
$('#quantity').val(quantity + 1);
// Increment
});
$('.quantity-left-minus').click(function(e) {
// Stop acting like a button
e.preventDefault();
// Get the field name
var quantity = parseInt($('#quantity').val());
// If is not undefined
// Increment
if (quantity > 0) {
$('#quantity').val(quantity - 1);
}
});
});
</script>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-23581568-13"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'UA-23581568-13');
</script>
</body>
<!-- Mirrored from preview.colorlib.com/theme/coffeeblend/checkout.html by HTTrack Website Copier/3.x [XR&CO'2014], Sun, 18 Apr 2021 16:32:50 GMT -->
</html>
<?php
//close database connection - initialize object to null
$pdo = null;
ob_end_flush();
?>