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

  • 0

This tutorial will take a different approach than usual. It will show, step-by-step, what it takes to write a custom PHP script that will change your Joomla admin password. This is useful to know in case you ever forget it

This tutorial is meant mainly for technologically curious Joomla users. If this subject doesn't interest you, then instead watch the accompanying tutorial that shows how to perform the same task using phpMyAdmin

1) Open your favorite text editor


 

Follow along with any typing you see exactly

 

2) Every PHP script should start and end like this


3) Next, we're going to store our username and the password we want to change ours to

 

This is done using variables that can be used later on in the script instead of typing the information there


 

Next, let's include the Joomla configuration file, since we'll need to access the Joomla database to change the password

 

The keyword require is generally used to include files that must be included in order for the script to function. If a required file cannot be found, PHP will cease processing the script


 

This line will allow us to access the settings found in configuration.php

 

 

With this line, we are now connected to the MySQL server


 

This will tell MySQL that we're going to be working with the Joomla database


 

Next, it's time to write the important part of the script -- the query that will update the user's password

 

The first part of the query lets MySQL know we want to do something with the users table


 

Joomla stores its passwords as a hash. This is an irreversible form of encryption. Specifially, it uses an algorithm called MD5

 

So, this second part says to set the password to the MD5 checksum of the contents of the $password variable


4) Finally, specify that only the user with the given username should have its password updated


5) This last line closes the connection to MySQL


6) The PHP script is complete! Save it, then upload the file to the Joomla directory on your web server

 

Make sure that the extension of the file is .php -- otherwise, you probably won't be able to run it

 

Once you've done that, type the URL to your Joomla site followed by the name of the PHP script. For example,  

http://www.yourdomain.com/joomla/resetpassword.php

 

Now that you've uploaded and run the script, let's go to Joomla and check that it worked

 

7) Log in


 

Success!

 

Now let's change our password in Joomla, since it stores extra information along with the MD5 hash of the password

 

8) Click Site

 

9) Go to User Manager

 

10) Click on the user


11) Change the user's password


12) And click Save

 

That's it! Your Joomla administrator password has now been updated

 

For obvious reasons, it would be best to delete your script from the server now that you've regained access to Joomla


Was this answer helpful?

« Back