Magento MySQL Script To Add New Admin User Programmatically By Custom Script

Hi Guys,

In Magento, you can add new admin user programmatically using custom PHP script.
You need to write some MySQL queries to database to create admin user.
To add new admin user, you can use the following code snippet:

LOCK TABLES `admin_role` WRITE , `admin_user` WRITE;

SET @SALT = "rp";
SET @PASS = CONCAT(MD5(CONCAT( @SALT , "password123") ), CONCAT(":", @SALT ));
SELECT @EXTRA := MAX(extra) FROM admin_user WHERE extra IS NOT NULL;

INSERT INTO `admin_user` (firstname,lastname,email,username,password,created,lognum,reload_acl_flag,is_active,extra,rp_token_created_at)
VALUES ('Firstname','Lastname','test@mail.com','myuser',@PASS,NOW(),0,0,1,@EXTRA,NOW());

INSERT INTO `admin_role` (parent_id,tree_level,sort_order,role_type,user_id,role_name)
VALUES (1,2,0,'U',(SELECT user_id FROM admin_user WHERE username = 'newuser'),'Firstname');

UNLOCK TABLES;
-----------------------------------OR--------------------------------
You can use the MySQL phpmyadmin console to user directly from database where you need to provide password as md5 encrypted which you can select from dropdown options.

Advertisements

Leave a Reply

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

WordPress.com Logo

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s