Magento 1.9 – Admin Login Error: Access Denied

adminadmin-paneladministrationmagento-1.9

I have installed magento on one of my site but I am not able to login in to the admin of site. Database table 'admin_user' is empty. It give me error:

    Access denied.

enter image description here

How can login into admin of site?

What I already did:

  1. Imported table 'admin_user' from local and inserted data on live database. It didn't work.
  2. Gone through these links: http://www.crucialwebhost.com/kb/how-to-reset-your-magento-password/, https://wiki.magento.com/display/m1wiki/Resetting+the+admin+Password
  3. Checked https://magento.stackexchange.com/ questions related to admin login issue.

Error produce:

  1. I created a database and imported sample data into it.
  2. Install a fresh magento site and after installing I used database created in 1st step and all these are on same hosting.

Details:

  1. Fresh magento version 1.9.2.1
  2. Sample data version used 1.9.0.0
  3. I have to do this because I could not install magento on sample database table.
  4. Front-end working fine except few images are not displaying but thats not a issue here.

Anyone might have faced such issue or may face sometime. So what are the ways to login to admin of site?

Best Answer

In the admin_rule table there should be an entry with record

INSERT INTO `admin_rule` (`rule_id`, `role_id`, `resource_id`, `privileges`, `assert_id`, `role_type`, `permission`) VALUES
(1, 1, 'all', NULL, 0, 'G', 'allow');

For admin_role table

INSERT INTO `admin_role` (`role_id`, `parent_id`, `tree_level`, `sort_order`, `role_type`, `user_id`, `role_name`, `gws_is_all`, `gws_websites`, `gws_store_groups`) VALUES
(1, 0, 1, 1, 'G', 0, 'Administrators', 1, NULL, NULL);

And create one admin user from root file using below script and try to login with that detail and see if that work.

<?php

# Create New admin User programmatically.
require_once('./app/Mage.php');
umask(0);
Mage::app();

try {
    $user = Mage::getModel('admin/user')
            ->setData(array(
                'username' => 'admin1',
                'firstname' => 'Admin',
                'lastname' => 'Admin',
                'email' => 'admin@test.com',
                'password' => 'admin123',
                'is_active' => 1
            ))->save();
}
catch (Exception $e) {
    echo $e->getMessage();
    exit;
}

//Assign Role Id
try {
    $user->setRoleIds(array(1))  //Administrator role id is 1 ,Here you can assign other roles ids
            ->setRoleUserId($user->getUserId())
            ->saveRelations();
}
catch (Exception $e) {
    echo $e->getMessage();
    exit;
}

echo "User created successfully";
?>
Related Topic