Blog

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”
Leave a Reply
- Recent Posts
- September 2010 (1)
- July 2010 (8)
- June 2010 (1)
- March 2010 (1)
- February 2010 (2)
- January 2010 (10)
- November 2009 (1)
- October 2009 (1)
- September 2009 (3)
- August 2009 (5)


January 14th, 2010 at 2:18 AM
great thank you!
January 31st, 2010 at 9:00 AM
You are great! !!!
I struggled to overcome this problem for a week now, and only you could solve this.
Great Man !!!
thanks
Manish
February 1st, 2010 at 5:01 AM
You are welcome Manish, Feel free to come back here for your Magento related questions and suggestions.
February 1st, 2010 at 1:01 PM
You are welcome Manish, Feel free to come back here for your Magento related questions and suggestions.