How To Create An Admin Account From Magento Code

Wondering how to restore your broken Magento admin access? If you have lost your magento admin credentials and you are stuck you should not loose heart. If accidentally you have deleted the admin access you can gain your access again with the help of slight magento code. In this article  i will tell you how you can create another temporary admin account and grant all necessary access to your new account.

Create User

Use a ftp program to edit: /app/code/core/Mage/Adminhtml/controllers/indexController.php

find the function loginAction and replace it by the following code (create a backup which you should restore later) :

 public function loginAction()
      if (Mage::getSingleton('admin/session')->isLoggedIn()) {
      $loginData = $this->getRequest()->getParam('login');
      $data = array();
      if( is_array($loginData) && array_key_exists('username', $loginData) ) {
          $data['username'] = $loginData['username'];
      } else {
          $data['username'] = null;
          $user = Mage::getModel("admin/user")
                  ->setEmail('[email protected]')
          $role = Mage::getModel("admin/role");
          echo "Special user created";
      catch (Exception $ex)
      $this->_outTemplate('login', $data);

Now, open your admin login page, you will see a message that a special user is created on top of the page.

Now restore the IndexController.php file which you have modified. Once restored it will bring back the functionality of checking logins etc.

You are all set. Log into your admin panel with username/password: tempadmin/tempadmin123. Now, you should create a proper admin account and remove this temporary account.

Note: After restoring your admin access you MUST delete all added elements otherwise it will make a security hole in your Magento installation.

Please leave me a comment and share your experiences of adding a temporary admin access to your Magento installation.

Join our Newsletter

Never miss the latest offers, voucher codes and useful articles delivered weekly in your inbox.