-
Notifications
You must be signed in to change notification settings - Fork 15
/
forgot.php
174 lines (141 loc) · 6.29 KB
/
forgot.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
<?php
session_start();
require_once "includes/connection.php";
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
function sendMail($email,$reset_token)
{
require('PHPMailer/PHPMailer.php');
require('PHPMailer/SMTP.php');
require('PHPMailer/Exception.php');
$mail = new PHPMailer(true);
try {
$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 = '[email protected]'; //SMTP username
$mail->Password = 'YourAppPassword'; //SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
$mail->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
//Recipients
$mail->setFrom('[email protected]', 'Taaza Restaurant');
$mail->addAddress($email); //Add a recipient
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'Password reset - Taaza';
$mail->Body = "<b style='color:blue'>We got a request from you to reset your password !</b><br>
Click the button below to reset your password<br>
<a href='http://localhost/taaza/reset_pass.php?email=$email&reset_token=$reset_token'>Reset password</a>
<br><p style='color:red'>Enjoy our services, hearty welcome from Taaza</p>
";
// Disable SSL certificate verification, because error occured for me
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->send();
return true;
} catch (Exception $e) {
return false;
}
} // Mail sending function ends
if(isset($_POST['reset']))
{
$email = mysqli_real_escape_string($conn, $_POST['email']); // Escape user input
$query = "SELECT * FROM `registered_users` WHERE `email`='$email'";
$result = mysqli_query($conn, $query);
if($result)
{
if(mysqli_num_rows($result)==1)
{
$reset_token = bin2hex(random_bytes(16));
date_default_timezone_set('Asia/Kolkata'); // Corrected function name
$date = date("Y-m-d");
$query = "UPDATE `registered_users` SET `resettoken`='$reset_token', `resettokenexpire`='$date' WHERE `email`='$email'";
if(mysqli_query($conn,$query) && sendMail($_POST['email'],$reset_token))
{
echo "
<script>
alert('Reset link sent to mail successfully');
window.location.href='new-login.php';
</script>
";
}
else
{
echo "
<script>
alert('UNKNOWN ISSUE: cannot run your request');
window.location.href='forgot.php';
</script>
";
}
}
else
{
echo "
<script>
alert('Email not registered');
window.location.href='forgot.php';
</script>
";
}
}
else
{
echo "
<script>
alert('UNKNOWN ISSUE: cannot run your request');
window.location.href='forgot.php';
</script>
";
}
}
?>
<?php require "includes/header.php"; ?>
<section class="home" id="home">
<div class="home-left">
<div class="container">
<div class="form-container1">
<div class="form-title"><b>Reset password</b></div>
<form action="#" method="POST">
<!-- Login Information -->
<div class="form-section">
<div class="form-field">
<label for="email">Email</label>
<input style="width: 300px;" type="email" id="email" name="email" placeholder="Type your registered e-mail" required>
</div>
<div class="form-field">
</div>
</div>
<div class="form-section">
</div>
<div class="form-section">
</div>
<button type="submit" name="reset" class="login-btn">Send link</button>
</form>
<br><center>
<div class="form-question"><u><a href="new-login.php" style="display: inline; color: #216aca;" onmouseover="this.style.color='#03d9ff'" onmouseout="this.style.color='#216aca'">< back to login</h3></a></u></div>
</center>
</div>
</div>
</div>
<div class="home-right" style="margin-top: 1cm;">
<img src="./assets/images/food1.png" alt="food image" class="food-img food-1" width="200" loading="lazy">
<img src="./assets/images/food2.png" alt="food image" class="food-img food-2" width="200" loading="lazy">
<img src="./assets/images/food3.png" alt="food image" class="food-img food-3" width="200" loading="lazy">
<img src="./assets/images/dialog-1.svg" alt="dialog" class="dialog dialog-1" width="230">
<img src="./assets/images/dialog-2.svg" alt="dialog" class="dialog dialog-2" width="230">
<img src="./assets/images/circle.svg" alt="circle shape" class="shape shape-1" width="25">
<img src="./assets/images/circle.svg" alt="circle shape" class="shape shape-2" width="15">
<img src="./assets/images/circle.svg" alt="circle shape" class="shape shape-3" width="30">
<img src="./assets/images/ring.svg" alt="ring shape" class="shape shape-4" width="60">
<img src="./assets/images/ring.svg" alt="ring shape" class="shape shape-5" width="40">
</div>
</section>
</header>
<?php require "includes/footer.php"; ?>