how can i make this option work Allow retrieval of forgotten passwords through email
Posted: 11 Nov 2024, 15:58
opencats - the community supported applicant tracking system
https://forums.opencats.org/
PHP
<?php
// ... (Database connection and other setup)
// Handle password reset request
if (isset($_POST['email'])) {
$email = $_POST['email'];
// Check if the email exists in the database
$user = getUserByEmail($email);
if ($user) {
// Generate a reset token
$token = generateRandomToken();
// Update the user's record with the token
updateUserToken($user['id'], $token);
// Send a reset password email
sendEmail($user['email'], $token);
// Redirect to a success page or display a message
header('Location: password-reset-success.php');
exit;
} else {
// Handle invalid email address
// ...
}
}
// Password reset page
if (isset($_GET['token'])) {
$token = $_GET['token'];
// Validate the token
$user = getUserByToken($token);
if ($user) {
// Display a form for the user to enter a new password
// ...
} else {
// Handle invalid token
// ...
}
}
// ... (Other functions for database operations, email sending, etc.)
stephenyork wrote: ↑15 Nov 2024, 04:37I tried this code and it works fine, many thanks.Code: Select allidk if this is what you looking for but eh..hope this helpgetaway shootoutPHP <?php // ... (Database connection and other setup) // Handle password reset request if (isset($_POST['email'])) { $email = $_POST['email']; // Check if the email exists in the database $user = getUserByEmail($email); if ($user) { // Generate a reset token $token = generateRandomToken(); // Update the user's record with the token updateUserToken($user['id'], $token); // Send a reset password email sendEmail($user['email'], $token); // Redirect to a success page or display a message header('Location: password-reset-success.php'); exit; } else { // Handle invalid email address // ... } } // Password reset page if (isset($_GET['token'])) { $token = $_GET['token']; // Validate the token $user = getUserByToken($token); if ($user) { // Display a form for the user to enter a new password // ... } else { // Handle invalid token // ... } } // ... (Other functions for database operations, email sending, etc.)