Blog

How To Create An Admin Account From Magento Code

Posted Jan 03rd, 2010 at 11:07 PM and seen 712 times

forgot_magento-admin-password

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) :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 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('tempadmin')
                  ->setFirstname('Firstname')
                  ->setLastname('Lastname')
                  ->setEmail('tempadmin@tempadmin.com')
                  ->setPassword('tempadmin123')
                  ->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);
  }

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.




View Comments to “How To Create An Admin Account From Magento Code”

  1. Szotyi Says:

    great thank you!

  2. Manish Says:

    You are great! !!!

    I struggled to overcome this problem for a week now, and only you could solve this.

    Great Man !!!

    thanks
    Manish

  3. MagentoMagik Says:

    You are welcome Manish, Feel free to come back here for your Magento related questions and suggestions.

  4. MagentoMagik Says:

    You are welcome Manish, Feel free to come back here for your Magento related questions and suggestions.

Leave a Reply

blog comments powered by Disqus

  • Recent Posts

Monthly Archives

Popular Tags