-
Notifications
You must be signed in to change notification settings - Fork 2
/
send_reset_link.php
189 lines (140 loc) · 6.34 KB
/
send_reset_link.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
<?php
/**
* Displays Single Input Field asking user to enter an Email to Recieve the Password Link On.
* On Form Submission It checks if the Email Entered is Registered with WYDRN Service and pushes an email if yes.
* 1) send_reset_link.php (Sends the Reset Link)
* 2) reset_pass.php (Upon Clicking the Link, user arrives here and is asked to enter a new password)
* 3) submit_new.php (Logic to update the database with the new password)
*
* @version PHP 8.0.12
* @since June 2022
* @author AtharvaShah
*/
require("connection.php");
require("functions.php");
// DO NOT INCLUDE THE HEADER BECAUSE USER IS NOT LOGGED IN! IT WILL BE INCLUDED IN THE LOGIN PAGE.
if (isset($_POST['submit_email']) && $_POST['email']) {
$email = mysqli_real_escape_string($con, $_POST['email']);
// Check if the email is registered with WYDRN
$select = mysqli_query($con, "SELECT `email`, `password` FROM `users` WHERE `email`='$email'");
if (mysqli_num_rows($select) == 1) {
// echo mysqli_num_rows($select);
while ($row = mysqli_fetch_array($select)) {
$email = ($row['email']);
$pass = ($row['password']);
}
// $link="<img src='images/website/logo.png' alt='WYDRN' width=100' height='100' style='margin-left:75px;'>";
// $link.="<br><br><br>";
$link = "<button style='padding:20px;'>";
$link .= "<a style='text-decoration: none;' href='localhost/WYDRN/reset_pass.php?key=" . $email . "&reset=" . $pass . "'" . ">Click Here To Reset Password</a>";
$link .= '</button>';
// Check if mail was sent successfully from server side
if (send_reset_link($email, $link)) {
// echo "Reset Link Sent to Your Email";
} else {
echo "<center><div class='alert alert-danger w-25 text-center' style='position: absolute; top: 20px; left: 570px;z-index:500;' role='alert'>
Server encountered an error while sending the reset link. Please try again later.
</div></center>";
}
} else {
echo "<center><div class='alert alert-danger w-25 text-center' style='position: absolute; top: 20px; left: 570px;z-index:500;' role='alert'>
Email is not registered!
</div></center>";
}
}
mysqli_close($con);
?>
<!-------------------------------------------------------------------------------------
HTML PART
------------------------------------------------------------------------------------->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="sends reset password link to the user's email" />
<meta name="keywords" content="WYDRN, send reset link" />
<title> WYDRN - Password Reset</title>
<link rel="stylesheet" href="css/others/bootstrap-reboot.min.css">
<link rel="stylesheet" href="css/others/bootstrap-grid.min.css">
<link rel="stylesheet" href="css/others/ionicons.min.css">
<link rel="stylesheet" href="css/utility.css">
<link rel="icon" type="image/png" href="images/website/favicons/favicon-32x32.png" sizes="32x32">
<link rel="apple-touch-icon" href="images/website/favicons/apple-touch-icon.png">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
<!-- Sweet Alert (Beautiful looking alert plugin-->
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
</head>
<!-- Body Begins -->
<body>
<div class="sign section--bg" data-bg="images/website/assets/abstract/section.jpg">
<div class="container">
<div class="row">
<div class="col-12">
<div class="sign__content">
<form method="post" action="send_reset_link.php" class="sign__form" onsubmit="return validation();">
<a href="login.php" class="sign__logo">
<img src="images/website/logo.png" alt="">
</a>
<div class="sign__group">
<input type="text" id="email" class="sign__input" placeholder="Email" name="email" required>
</div>
<div class="sign__group sign__group--checkbox">
<input type="checkbox" checked="checked">
<label for="remember" class="agree-label">I agree to the <a href="privacy_policy.php">Privacy Policy</a></label>
</div>
<input type="submit" value="Send" name="submit_email" class="forgot-mail-submit" id="mbtn">
<span class="sign__text">We will E-mail you the password reset link </span>
</form>
<!-- end authorization form -->
</div>
</div>
</div>
</div>
</div>
<!-------------------------------------------------------------------------------------
JAVASCRIPT PART
------------------------------------------------------------------------------------->
<script>
// To prevent form resubmission when page is refreshed (F5 / CTRL+R)
if (window.history.replaceState) {
window.history.replaceState(null, null, window.location.href);
}
function validation(){
var email = document.getElementById("email").value;
var re = /\S+@\S+\.\S+/;
if (!re.test(email)) {
//sweet alert plugin to display error message. IT REPLACES the JS alert() function.
swal({
title: "Email Invalid",
text: "Please enter a valid email address. Don't hoax.",
icon: "warning",
button: "Retry",
});
return false;
}
else{
swal({
title: "Reset Link Sent",
text: "Check your email for the reset link",
icon: "success",
button: "OK",
});
return true;
}
}
</script>
<!-- JS -->
<script src="js/jquery-3.5.1.min.js"></script>
<script src="js/jquery.magnific-popup.min.js"></script>
<script src="js/jquery.mCustomScrollbar.min.js"></script>
<script src="js/select2.min.js"></script>
<script src="js/utility.js"></script>
</body>
</html>
<!-------------------------------------------------------------------------------------
PHP PART
------------------------------------------------------------------------------------->
<?php
?>