-
Notifications
You must be signed in to change notification settings - Fork 0
/
forgotpassword.php
257 lines (211 loc) · 9.43 KB
/
forgotpassword.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<?php
session_start();
use PHPMailer\PHPMailer\PHPMailer;
include_once 'Connect/connection.php';
$Reset_pswd_Through_Email=$Email_Not_Found=$MailerError=$email_required=null;
if ($_SERVER["REQUEST_METHOD"] == "POST"){
if(isset($_POST['submit_forgot_pswd'])){
$email = test_input($_POST['email']);
$sql = "SELECT * FROM `users` WHERE email = '$email'";
$res = mysqli_query($con, $sql);
$count = mysqli_num_rows($res);
if (empty($email)) {
$email_required='<script type="text/javascript">toastr.error("Email field is required !")</script>';
}else{
if($count == 1){
require_once 'PHPMailer\PHPMailer.php';
require_once 'PHPMailer\SMTP.php';
require_once 'PHPMailer\Exception.php';
$r = mysqli_fetch_assoc($res);
$password = $r['password'];
$link="<a href='ResetPassword.php'>Reset password</a>";
//Encrypting email
$email_string=$email;
// Store the cipher method
$ciphering = "AES-128-CTR";
// Use OpenSSl Encryption method
$iv_length = openssl_cipher_iv_length($ciphering);
$options = 0;
// Non-NULL Initialization Vector for encryption
$encryption_iv = '1234567891011121';
// Store the encryption key
$encryption_key = "Fav";
// Use openssl_encrypt() function to encrypt the data
$encrypted_email = openssl_encrypt($email_string, $ciphering,
$encryption_key, $options, $encryption_iv);
try {
//Server settings
// $mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail=new PHPMailer(); //Enable verbose debug output
$mail->isSMTP(); //Send using SMTP
$mail->Host = 'smtp.gmail.com'; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = 'bikmangeek@gmail.com'; //SMTP username
$mail->Password = 'hpvrdqffxfmpsgku'; //SMTP password
$mail->SMTPSecure = 'tls' ; //tls; //Enable implicit TLS encryption
$mail->Port = 587; //587; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
//Content
$mail->isHTML(true);
$mail->setFrom($email,'Fav-system');
$mail->addAddress($email); //Set email format to HTML
$mail->Subject = "Your Recovered Password";
$mail->Body = "Please use this link to reset password " .'<a href="http://localhost/project/Fav_system/ResetPassword.php?email='.$encrypted_email.'">Reset Password here : '.$encrypted_email.'</a>';
$mail->send();
$Reset_pswd_Through_Email='<script type="text/javascript">toastr.success("We mailed you a reset link !")</script>';
} catch (Exception $e) {
$MailerError='<script type="text/javascript">toastr.error("Message could not be sent. Mailer Error: {$mail->ErrorInfo}")</script>';
}
}else{
$Email_Not_Found='<script type="text/javascript">toastr.error("Email not found in our records !")</script>';
}
}
}
}
function test_input($data){
$data=trim($data);
$data=stripslashes($data);
$data=htmlspecialchars($data);
return $data;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>FAV_system</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--==================================================================-->
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.0.1/css/toastr.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.0.1/js/toastr.js"></script>
<link rel="stylesheet" href="style/plugins/fontawesome-free/css/all.min.css">
<link rel="stylesheet" href="style/login/login.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway:400,700">
<script src="style/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="jquery.min.js"></script>
<script src="jquery.js"></script>
<style type="text/css">
.card_profile{
justify-content: center;
display: flex;
align-items: center;
}
#errorField{
justify-content: center;
display: flex;
align-items: center;
margin-top: 10px;
color:white;
font-size: 20px;
padding-left: 5px;
border-radius: 5px;
width:100%;
}
.card_title{
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
transition: 0.3s;
/* width: 70%; */
text-align: center;
background-color: white;
font-family: sans-serif;
font-weight: bold;
}
.card_title h2{
font-family: serif;
padding: 15px;
}
.card {
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
transition: 0.3s;
width:100%;
}
.card:hover {
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
}
.container {
padding: 2px 16px;
text-align: center;
font-family: serif;
}
#forgotpswd a{
background-color: #fff;
color: #4C489D;
padding: 5px;
border-radius:30px;
box-shadow: 0px 2px 2px #5C5696;
text-decoration: none;
font-weight: 300;
}
#forgotpswd:hover{
border-color: #6A679E;
outline: none;
}
</style>
<!--===============================================================================================-->
</head>
<body>
<?php echo $Reset_pswd_Through_Email.$MailerError.$Email_Not_Found.$email_required;?>
<div class="card_profile">
<div class="card">
<div class="card_title">
<h2><b>Fav system</b></h2>
</div>
</div>
</div>
<div class="container">
<div class="screen">
<div class="screen__content">
<h1>Forgot <span style="color:white;">Password</span> </h1>
<form class="login" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method="POST">
<div class="login__field">
<i class="login__icon fas fa-envelope"></i>
<input type="email" class="login__input" placeholder="Email" name="email">
</div>
<button class="button login__submit" type="submit" name="submit_forgot_pswd">
<i class="button__icon fas fa-cool"></i>
<span class="button__text">Send reset link</span>
<i class="button__icon fas fa-paper-plane"></i>
</button>
</form>
<!-- <div class="social-login">
<h3>log in via</h3>
<div class="social-icons">
<a href="#" class="social-login__icon fab fa-instagram"></a>
<a href="#" class="social-login__icon fab fa-facebook"></a>
<a href="#" class="social-login__icon fab fa-twitter"></a>
</div>
</div> -->
<div id="forgotpswd">
<a href="index.php"><i class="fas fa-chevron-left"></i> Back to login</a>
</div>
</div>
<div class="screen__background">
<span class="screen__background__shape screen__background__shape4"></span>
<span class="screen__background__shape screen__background__shape3"></span>
<span class="screen__background__shape screen__background__shape2"></span>
<span class="screen__background__shape screen__background__shape1"></span>
</div>
</div>
</div>
<script>
(function ($) {
"use strict";
var showPass = 0;
$('.btn-show-pass').on('click', function(){
if(showPass == 0) {
$(this).next('input').attr('type','text');
$(this).find('i').removeClass('zmdi-eye');
$(this).find('i').addClass('fas fa-eye');
showPass = 1;
}
else {
$(this).next('input').attr('type','password');
$(this).find('i').addClass('fas fa-eye');
$(this).find('i').removeClass('zmdi-eye');
showPass = 0;
}
});
})(jQuery);
</script>
</body>
</html>