-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforgot_process.php
More file actions
36 lines (29 loc) · 1.16 KB
/
forgot_process.php
File metadata and controls
36 lines (29 loc) · 1.16 KB
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
require 'db.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = trim($_POST['email'] ?? '');
if (empty($email)) {
http_response_code(400);
echo json_encode(['success' => false, 'message' => 'Email required']);
exit();
}
// Check if email exists
$check = $conn->prepare("SELECT id FROM users WHERE email = ?");
$check->bind_param("s", $email);
$check->execute();
if ($check->get_result()->num_rows > 0) {
$token = bin2hex(random_bytes(32));
$expires = date("Y-m-d H:i:s", strtotime("+1 hour"));
$stmt = $conn->prepare("INSERT INTO password_resets (email, token, expires) VALUES (?, ?, ?)");
$stmt->bind_param("sss", $email, $token, $expires);
$stmt->execute();
// TODO: Send email with reset link using email_config.php
// For now, log the token for development
error_log("Password reset token for $email: $token");
echo json_encode(['success' => true, 'message' => 'Reset link sent to email']);
} else {
http_response_code(404);
echo json_encode(['success' => false, 'message' => 'Email not found']);
}
}
?>