-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforgotpass.php
56 lines (47 loc) · 1.76 KB
/
forgotpass.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
<?php
include("./php/database.php");
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'phpmailer/src/Exception.php';
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';
$response = "";
if($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST['username'];
$_SESSION['user'] = $username;
$sql = "SELECT * FROM login WHERE Email='$username'";
$result = $conn->query($sql);
$otp = random_int(100000, 999999);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$sql = "UPDATE login SET Otp='$otp' WHERE Email ='$username'";
$result = $conn->query($sql);
if ($result) {
try {
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'examplepassword';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->setFrom('[email protected]');
$mail->addAddress($username);
$mail->isHTML(true);
$mail->Subject = "RESET PASSWORD";
$mail->Body = "HII $username. Here is your OTP: $otp";
$mail->send();
$response = "Check your email to reset your account.";
} catch (Exception $e) {
$response = "Email sending failed: " . $mail->ErrorInfo;
}
} else {
$response = "Unable to send OTP.";
}
} else {
$response = "Input valid email address.";
}
}
echo $response;
?>