joomla-4-file-editor

Joomla 2.5 setup series

10. How to reset your Joomla admin password using a custom PHP script

We will create a PHP script to reset our admin password in Joomla.

Using a text editor enter the code exactly as illustrated here

The value entered for the variable $password (password1234) will be the new password for your admin user account

1) Now select the Save menu option. Give the file a name like ‘resetadmin.php’ and then upload it to your Joomla web site root or home directory.  Run the script by entering http://www.yourdomain.com/resetadmin.php from your browser

2) Now log in to your admin panel using the password you entered in the previously written script

3) Enter your User Name

4) Next enter the password from your script

5) Now click the Log in button

6) After logging in, select the User Manager icon.

7) Click the name of the account you just reset the password for

8) Here you can change the password and Save the record to update linked tables properly

9) Reenter your password in the Confirm Password field

10) Click the Save & Close button

You now know how to reset your Joomla admin password using a custom PHP script

Reset Joomla Admin Password Using Custom PHP Script

If you’ve lost access to your Joomla admin account and need to reset your password, you can do so using a custom PHP script. Follow the steps below to create and execute the script to reset your Joomla admin password.

Step-by-Step Guide

Step 1: Create the PHP Script

Create a new PHP file (e.g., reset_admin_password.php) and add the following code:

<?php
// Database configuration
$host = 'localhost';
$db = 'your_joomla_database';
$user = 'your_database_username';
$pass = 'your_database_password';
$prefix = 'jos_'; // Change this if your Joomla table prefix is different

// New password
$new_password = 'your_new_password';

// Hash the new password using Joomla's hashing method
$options = [
    'cost' => 10,
];
$hashed_password = password_hash($new_password, PASSWORD_BCRYPT, $options);

// Create a connection to the database
$mysqli = new mysqli($host, $user, $pass, $db);

// Check the connection
if ($mysqli->connect_error) {
    die('Connection failed: ' . $mysqli->connect_error);
}

// Update the admin user password
$sql = "UPDATE " . $prefix . "users SET password = '$hashed_password' WHERE username = 'admin'";

if ($mysqli->query($sql) === TRUE) {
    echo "Password reset successfully!";
} else {
    echo "Error updating password: " . $mysqli->error;
}

// Close the connection
$mysqli->close();
?>
            

Warning: Replace your_joomla_database, your_database_username, your_database_password, your_new_password, and adjust the table prefix if necessary.

Step 2: Upload the Script

Upload the reset_admin_password.php file to the root directory of your Joomla installation using an FTP client or your hosting control panel’s file manager.

Step 3: Execute the Script

Open your web browser and navigate to the following URL:

http://yourdomain.com/reset_admin_password.php

Make sure to replace yourdomain.com with your actual domain name. You should see a message indicating whether the password reset was successful or if there was an error.

Step 4: Delete the Script

For security reasons, immediately delete the reset_admin_password.php file from your server after resetting your password.

Conclusion

By following these steps, you can reset your Joomla admin password using a custom PHP script. This method is useful if you’ve lost access to your admin account and need to regain control of your Joomla site. Always remember to delete the script after use to maintain the security of your site.

Similar Posts