-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreset_password.php
More file actions
36 lines (28 loc) · 908 Bytes
/
reset_password.php
File metadata and controls
36 lines (28 loc) · 908 Bytes
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
<?php
include('dabcon.php'); // Assuming db connection script
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
$otp = $_POST['otp'];
// Debug output to check the value of $otp
echo "Debug: OTP received is " . $otp . "<br>";
$sql = "SELECT * FROM otp_verification WHERE otp='$otp'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$email = $row['email'];
$sql = "UPDATE users SET password='$password' WHERE email='$email'";
if ($conn->query($sql) === TRUE) {
$sql = "DELETE FROM otp_verification WHERE otp='$otp'";
$conn->query($sql);
header('Location: index.html');
exit();
} else {
echo "Error updating password: " . $conn->error;
}
} else {
echo "Invalid request.";
}
$conn->close();
?>