-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforgot-password.php
More file actions
107 lines (93 loc) · 4.6 KB
/
forgot-password.php
File metadata and controls
107 lines (93 loc) · 4.6 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
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
<?php
require_once 'config.php';
$message = '';
$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = sanitize($_POST['email']);
if (empty($email)) {
$error = 'Email address is required';
} else {
// Check if email exists in database
$stmt = $pdo->prepare("SELECT * FROM users WHERE email = ?");
$stmt->execute([$email]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
if ($user) {
// Generate reset token (in a real app, you'd create a proper token)
$token = bin2hex(random_bytes(32));
$expires = date('Y-m-d H:i:s', strtotime('+1 hour'));
// Store token in database (you'd need a password_resets table)
// $pdo->prepare("INSERT INTO password_resets ...")->execute([...]);
// In a real app, you would send an email with a reset link
$message = 'If an account exists with this email, you will receive a password reset link shortly.';
} else {
// Don't reveal whether the email exists or not
$message = 'If an account exists with this email, you will receive a password reset link shortly.';
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Forgot Password - Ecommerce</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
</head>
<body class="bg-gray-100">
<?php include 'includes/header.php'; ?>
<div class="min-h-screen flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8">
<div class="max-w-md w-full space-y-8 bg-white p-10 rounded-lg shadow-xl">
<div class="text-center">
<h2 class="mt-6 text-3xl font-extrabold text-gray-900">
Forgot your password?
</h2>
<p class="mt-2 text-sm text-gray-600">
Enter your email address and we'll send you a link to reset your password.
</p>
</div>
<?php if ($error): ?>
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative mb-4" role="alert">
<?php echo htmlspecialchars($error); ?>
</div>
<?php endif; ?>
<?php if ($message): ?>
<div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded relative mb-4" role="alert">
<?php echo htmlspecialchars($message); ?>
</div>
<?php endif; ?>
<form class="mt-8 space-y-6" method="POST">
<div class="rounded-md shadow-sm space-y-4">
<div>
<label for="email" class="block text-sm font-medium text-gray-700">Email address</label>
<div class="mt-1 relative rounded-md shadow-sm">
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
<i class="fas fa-envelope text-gray-400"></i>
</div>
<input id="email" name="email" type="email" required
class="py-3 pl-10 block w-full border border-gray-300 rounded-md focus:ring-indigo-500 focus:border-indigo-500"
placeholder="Enter your email">
</div>
</div>
</div>
<div>
<button type="submit"
class="group relative w-full flex justify-center py-3 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
<span class="absolute left-0 inset-y-0 flex items-center pl-3">
<i class="fas fa-paper-plane text-indigo-300 group-hover:text-indigo-200"></i>
</span>
Send Reset Link
</button>
</div>
</form>
<div class="text-center mt-4">
<a href="login.php" class="font-medium text-indigo-600 hover:text-indigo-500">
Back to login
</a>
</div>
</div>
</div>
<?php include 'includes/footer.php'; ?>
</body>
</html>