-
Notifications
You must be signed in to change notification settings - Fork 0
/
forgot_password.php
108 lines (93 loc) · 2.87 KB
/
forgot_password.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
<?php
session_start();
require 'vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "signup";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
function sendOTP($email, $otp) {
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'your gmail';
$mail->Password = 'your app pw';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
$mail->setFrom('your gmail', 'SyncSpace');
$mail->addAddress($email);
$mail->isHTML(true);
$mail->Subject = 'OTP for Password Reset';
$mail->Body = "Your OTP for password reset is: $otp";
$mail->send();
return true;
} catch (Exception $e) {
return false;
}
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST['email'])) {
$email = $_POST['email'];
$stmt = $conn->prepare("SELECT * FROM registration WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$otp = rand(100000, 999999);
$_SESSION['otp'] = $otp;
$_SESSION['email'] = $email;
if (sendOTP($email, $otp)) {
header("Location: verifyy_otp.php");
exit();
} else {
echo "Failed to send OTP.";
}
} else {
echo "Email not found.";
}
$stmt->close();
}
}
$conn->close();
?>
<!DOCTYPE html>
<html>
<head>
<title>Forgot Password</title>
<link rel="stylesheet" href="forgotpw.css">
</head>
<body>
<nav class="navbar" id="navbar">
<div class="navbar-container">
<div class="navbar-brand">
<div class="logo">
<img src="../MainProject/Media/logo.gif" loop>
</div>
</div>
<ul class="navbar-menu" id="navbar-menu">
<li><a href="enter.html">Back</a></li>
</ul>
<div class="navbar-toggle" id="navbar-toggle">
<span></span>
<span></span>
<span></span>
</div>
</div>
</nav>
<div class="sidebar">
</div>
<h2>Enter Your Registered Email Address</h2>
<form method="post" action="">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<button type="submit">Send OTP</button>
</form>
</body>
</html>