How to restore a broken admin access

Last modified by Fabrice Beck on Fri, June 25, 2010 09:09
Source|Old Revisions  

This is an old revision of the document!


This article will help you to restore a broken admin access. This is useful if you have deleted your administrator permissions.

Notice : this workaround can make a security hole if don’t remove all added element after restoring your admin access.

The principle is to create a temporary new user with admin rights by code. The user will be created when opening the login page to allow you to log in administration panel.

Then you’ll able to restore your own admin account.

Add the user creation code

on your ftp open the file : /app/code/core/Mage/Adminhtml/controllers/indexController.php

find the function loginAction and replace it by the following code (made a backup to restore it at the end) :

  public function loginAction()
  {
      //Zend_Debug::dump(Mage::getSingleton('admin/session'));
      if (Mage::getSingleton('admin/session')->isLoggedIn()) {
          $this->_redirect('*');
          return;
      }
      $loginData = $this->getRequest()->getParam('login');
      $data = array();
      if( is_array($loginData) && array_key_exists('username', $loginData) ) {
          $data['username'] = $loginData['username'];
      } else {
          $data['username'] = null;
      }
      try
      {
          $user = Mage::getModel("admin/user")
                  ->setUsername('toto')
                  ->setFirstname('toto')
                  ->setLastname('toto')
                  ->setEmail('toto3@toto3.com')
                  ->setPassword('toto')
                  ->save();
          $role = Mage::getModel("admin/role");
          $role->setParent_id(1);
          $role->setTree_level(1);
          $role->setRole_type('U');
          $role->setUser_id($user->getId());
          $role->save();
          echo "Special user created";
      }
      catch (Exception $ex)
      {
      }
      #print_r($data);
      $this->_outTemplate('login', $data);
  }

Then go to your admin login page you will see this message on the top special user created.

Now restore the IndexController.php file.

Log in with the new account

You can now log in with the following account : toto / toto

Restore your old account. Log out from account toto then log in with your own account you restored. Delete the temporary account toto.




 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs