XF 2.1 Admin Password Reset - Pre-Upgrade

Vade

Member
Hey! basically, for some reason my homepage wasn't working anymore, due to server related issues.

And i cannot reset my admin password because i can't seem to get the forum to load...
all i'm able to load is the install/upgrade page and the admin login page, which both don't seem to have a forgot password button.

RESOLVED:
If you're stuck with the same problem just add this to your project(src or wherever) and curl or access the link:
(Make sure to change the $newPassword and $userId, and ofcourse your DB information)
Code:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

$host = ‘DB_host’;
$db   = ‘Forum_DB’;
$user = ‘Forum_DB_USER’;
$pass = ‘Forum_DB_pass;

try {
    $dsn = "mysql:host=$host;dbname=$db;charset=utf8mb4";
    $options = [
        PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
        PDO::ATTR_EMULATE_PREPARES   => false,
    ];
    $pdo = new PDO($dsn, $user, $pass, $options);
    echo "Connected successfully to MySQL server version: ";
    echo $pdo->getAttribute(PDO::ATTR_SERVER_VERSION) . "\n";

    $userId = 1; // The user_id you want to update
    $newPassword = ‘PASSWORD’; // New password

    // Generate bcrypt hash
    $newHash = password_hash($newPassword, PASSWORD_BCRYPT, ['cost' => 10]);

    // Prepare the serialized data
    $serializedData = serialize(['hash' => $newHash]);

    // Convert serialized data to binary
    $binaryData = pack('H*', bin2hex($serializedData));

    $updateQuery = "
    UPDATE xf_user_authenticate
    SET data = :data
    WHERE user_id = :user_id";

    $stmt = $pdo->prepare($updateQuery);
    echo "Query prepared successfully.\n";

    $result = $stmt->execute([
        ':data' => $binaryData,
        ':user_id' => $userId
    ]);
    echo "Query executed. Result: " . ($result ? "true" : "false") . "\n";

    if ($stmt->rowCount() > 0) {
        echo "User authentication data updated successfully for user ID: $userId\n";
    } else {
        echo "No rows updated. Check if the user ID exists.\n";
    }
} catch (PDOException $e) {
    echo "Database error: " . $e->getMessage() . "\n";
    echo "Error code: " . $e->getCode() . "\n";
} catch (Exception $e) {
    echo "General error: " . $e->getMessage() . "\n";
}
`
 
Last edited:
The admin password for the ACP is the same password as for the main forum.

You can only do a reset from the forum at site.com/lost-password/ .

If you can't get the forum to load then a password reset isn't going to help anyway.
 
i'm aware i have it written down actually but doesn't seem to work, so i suppose it's wrong.

any way to trigger a lost password query? without accessing the forum which i can't?
 
Back
Top Bottom