Reset an administrator password or add a Magento admin user using MySQL

06 May

Reseting a password

Take a look at the admin_user table, here you can see the admin users records.

admin_user table

Let`s suppose that we need to reset a password for an existing user.
Click the ‘edit’ button

Edit record

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.

reset password- second step

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;

Copy the result.
Password hash
Paste into the MySQL script:

INSERT INTO admin_user
NULL user_id,
"ATWIX" firstname,
"DOT COM" lastname,
"" 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
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*, remove lines 16 and 17.
Now you are ready to run script:

Run MySQL 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.

New Admin User

2. Next we need to add record to admin_role table.

Add Admin Account

Here user_id – is ID of user that we have created. parent_id is role_id of Administrators record:

Getting parent_id

It is done. Test your new admin account.

Leave a comment

Posted by on May 6, 2013 in Magento


Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: