Magento create admin user programmatically

Here is custom script to create admin user programmatically.
# Create New admin User programmatically.
require_once('./app/Mage.php');
umask(0);
Mage: :app();

try {
$user = Mage: :getModel('admin/user')->setData(array(
        'username' => 'admin',
        'firstname' => 'Mage',
        'lastname' => 'Spider',
        'email' => 'info@magespider.com',
        'password' =>'admin123',
        'is_active' => 1
        ))->save();

} catch (Exception $e) {
    echo $e->getMessage();
    exit;
}

//Assign Role Id
try {
    $user->setRoleIds(array(1)) //Administrator role id is 1 ,Here you can assign other roles ids
    ->setRoleUserId($user->getUserId())
    ->saveRelations();

} catch (Exception $e) {
    echo $e->getMessage();
    exit;
}

echo "User created successfully";
  Put the above content in a magento root folder in a file and then browse the file. You are done with creating new admin user.
Pritesh Pritesh

Pritesh Pethani

Request a Quote!!

Share your concept and we will return to you within 24 hours. Let us work out the best software solution for you!

Let's Start
Whatspp