Reset an administrator password or add a Magento admin user using MySQL
Unable to log in to a Magento store’s backend? Don’t remember your admin password? Are you a Magento developer and want a quick and easy way to add an admin account to a client’s Magento store? If so, this article is for you.
First, we need access to the MySQL database. In most cases, phpMyAdmin is installed on the server. For this article, we will use this great tool.
Reseting a password
Take a look at the admin_user table, here you can see the admin users records.
Let`s suppose that we need to reset a password for an existing user.
Click the ‘edit’ button
Passwords stored in the database are MD5 encrypted, so we are going to use MD5 function. Note: Magento also uses a salt
to calculate a hash. In our case, this is just the two random characters. Here are the two steps to set a new password.
1. Make sure you select the MD5 function to be applied to the password field, paste your salt + password value in the field for password and click the ‘go’ button to save it. In this example, we are using ‘at’ for salt and ‘12345678’ for the password:
2. Once saved, click the ‘edit’ button one more time and add salt to the end of the password hash, so it will look like hash + ‘:’ + salt. Then click the ‘go’ button to save your changes.
Now you are able to log in with new password.
Adding an admin user account
In this section, we are going to build a MySQL script that you can use for adding a new admin account within seconds.
It is recommended to have a salted password hash ready. This is easy, you can generate it online here
, by running this PHP code (replace the sample pass and salt with yours):
$pass = "12345678";
$salt = "at";
Copy the result.
Paste into the MySQL script:
INSERT INTO admin_user
"DOT COM" lastname,
NOW( ) created,
(SELECT MAX(extra) FROM admin_user WHERE extra IS NOT NULL) extra,
INSERT into admin_role
(SELECT role_id FROM admin_role WHERE role_name = 'Administrators') parent_id,
(SELECT user_id FROM admin_user WHERE username = 'ATWIX') user_id,
Don’t forget to set your own values on lines 4-8, 26, 27.
If you use Magento CE 18.104.22.168-1.4.*, remove lines 16 and 17.
Now you are ready to run script:
That is it! Now you can execute script any time you need to add admin account.
If you are not comfortable using script than another way can meet your needs:
1. Click Insert button to make new admin_user record. Fill out necessary fields using existing record values and this manual as template.
2. Next we need to add record to admin_role table.
Here user_id – is ID of user that we have created. parent_id is role_id of Administrators record:
It is done. Test your new admin account.