Page 1 of 1

how can i make this option work Allow retrieval of forgotten passwords through email

Posted: 11 Nov 2024, 15:58
by Srikanth_ptc
Hello Everyone,

How can i make this option work Allow retrieval of forgotten passwords through email under the settings.

Image

Re: how can i make this option work Allow retrieval of forgotten passwords through email

Posted: 11 Nov 2024, 17:37
by RussH
This functionality isn't present in the code. I believe one of the developers was intending to complete it but never got around to it. It isn't hugely complex if you wanted to engage a developer and contrinute the code back to the project.

Re: how can i make this option work Allow retrieval of forgotten passwords through email

Posted: 15 Nov 2024, 04:37
by stephenyork
Code: Select all
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.)
idk if this is what you looking for but eh..hope this helpgetaway shootout

Re: how can i make this option work Allow retrieval of forgotten passwords through email

Posted: 29 Nov 2024, 07:45
by Stephen Ellison
stephenyork wrote: 15 Nov 2024, 04:37
Code: Select all
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.)
idk if this is what you looking for but eh..hope this helpgetaway shootout
I tried this code and it works fine, many thanks.