-
Notifications
You must be signed in to change notification settings - Fork 1
/
resetpassword.php
194 lines (140 loc) · 6.71 KB
/
resetpassword.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" type="image/x-icon" href="img/plismun19_a_favicon.png">
<title>PLISMUN</title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css">
<!-- Fonts -->
<link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="css/animate.css" rel="stylesheet" />
<!-- recycling css from signup page because the layout is basically the same and I can't be bothered to make a new file just for this-->
<link href="css/pages/signup.css" rel="stylesheet">
<link href="color/default.css" rel="stylesheet">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-120398250-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-120398250-1');
</script>
</head>
<body id="page-top" data-spy="scroll" data-target=".navbar-custom">
<!-- PHP -->
<?php
require_once('config.php');
// get values from path name
$email = $_GET['email'];
$token = $_GET['token'];
// validate token
$validationQuery = "SELECT resettoken FROM `users` WHERE email = '$email'";
$validationResult = mysqli_fetch_assoc(mysqli_query($link, $validationQuery));
$tokenValid = '';
if($validationResult["resettoken"] == $token && $validationResult["resettoken"] != null) {
$tokenValid = true;
} else {
$tokenValid = false;
}
// submit password reset form
if ($tokenValid && isset($_POST["submit"])) {
$password = $_POST['password'];
$confirmPassword = $_POST['confirmpassword'];
$errPassword = '';
$errConfirmpassword = '';
if (!$_POST['password']) {
$errPassword = 'Please enter a password';
}
if ($_POST['confirmpassword'] != $_POST['password']) {
$errConfirmpassword = 'Please repeat your password correctly';
}
if (!$errPassword && !$errConfirmpassword) {
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$query = "UPDATE `users` SET resettoken = null, password = '$hashed_password' WHERE email = '$email';";
$result = mysqli_query($link, $query);
if ($result) {
$resetResult = '<div class="alert alert-success">Password reset successful! Click <a href="apply">here</a> to login</div>';
} else {
$resetResult = '<div class="alert alert-danger">An error occurred while changing the password</div>';
}
}
}
?>
<!-- Preloader -->
<div id="preloader-overlay"></div>
<!-- navbar, inserted via js -->
<div id="header"></div>
<?php
if ($tokenValid)
{
?>
<div class="signup">
<div class="signup-window">
<div class="container">
<h2>Reset password</h2>
<form id="signup" class="form-horizontal" method="post" action="resetpassword?email=<?php echo $email;?>&token=<?php echo $token;?>">
<div class="form-group">
<div class="col-md-4 col-md-offset-4">
<?php echo $resetResult ?>
</div>
</div>
<div class="form-group row">
<label class="control-label col-sm-4" for="lastname">Password: </label>
<div class="col-md-4">
<input type="password" class="form-control" id="password" name="password" placeholder="Password" value="<?php echo $_POST['password']; ?>">
<?php echo "<p class='text-danger'><b>$errPassword</b></p>";?>
</div>
</div>
<div class="form-group row">
<label class="control-label col-sm-4" for="lastname">Confirm password:</label>
<div class="col-md-4">
<input type="password" class="form-control" id="confirmpassword" name="confirmpassword" placeholder="Confirm Password" value="<?php echo $_POST['confirmpassword']; ?>">
<?php echo "<p class='text-danger'><b>$errConfirmpassword</b></p>";?>
</div>
</div>
<input id="submit" name="submit" type="submit" class="btn btn-success btn-send col-md-4 col-md-offset-4" value="Reset password">
</form>
</div>
</div>
</div>
<?php } ?>
<?php
if (!$tokenValid) {
?>
<div class="signup">
<div class="signup-window">
<div class="container">
<div class="col-md-4 col-md-offset-4">
<div class="alert alert-danger">Reset password credentials incorrect. Please try again or resend the email <a href="forgotpassword">here</a></div>
</div>
</div>
</div>
</div>
<?php } ?>
<!-- footer-->
<div id="footer"></div>
<!-- /footer -->
<!-- Core JavaScript Files -->
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.scrollTo.js"></script>
<!--reveal while scrolling script-->
<script src="js/wow.min.js"></script>
<!-- Custom Theme JavaScript -->
<script src="js/custom.js"></script>
<!-- parallax script -->
<script src="js/parallax.min.js"></script>
<script type="text/javascript">
// include footer
$(function() {
$("#header").load("navbar");
$("#footer").load("footer");
$("#preloader-overlay").load("preloader");
});
</script>
</body>
</html>