Magento How To Create An Admin Account From 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() { //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('[email protected]') ->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.
(Source: www.magikcommerce.com)