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"; echo md5($salt.$pass).":".$salt;
INSERT INTO admin_user SELECT NULL user_id, "ATWIX" firstname, "DOT COM" lastname, "firstname.lastname@example.org" email, "atwix" username, "e58d34d72aefb6d6f6c6e419da695252:at" password, NOW( ) created, NULL modified, NULL logdate, 0 lognum, 0 reload_acl_flag, 1 is_active, (SELECT MAX(extra) FROM admin_user WHERE extra IS NOT NULL) extra, NULL rp_token, NOW() rp_token_created_at; INSERT into admin_role SELECT NULL role_id, (SELECT role_id FROM admin_role WHERE role_name = 'Administrators') parent_id, 2 tree_level, 0 sort_order, 'U' role_type, (SELECT user_id FROM admin_user WHERE username = 'ATWIX') user_id, 'ATWIX' role_name
Don’t forget to set your own values on lines 4-8, 26, 27.
Note: If you use Magento CE 184.108.40.206-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.
You may also want to read: