---
title: "How to Login in to Magento 2 Admin without Password? (Using Root Script)"
url: "https://magecomp.com/blog/login-in-to-magento-2-admin-without-password-using-root-script/"
date: "2025-01-17T06:58:07+00:00"
modified: "2025-01-17T07:11:14+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 511
reading_time: "3 min read"
summary: "Hello Magento Friends,"
description: "Learn how to log in to the Magento 2 Admin panel without a password using a root script"
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "Fixing: Failed to Load Resources Error After Installing Magento 2"
    url: "https://magecomp.com/blog/fixing-failed-to-load-resources-error-after-installing-magento-2/"
  - title: "How to Remove/Delete Product programmatically in Magento 2"
    url: "https://magecomp.com/blog/remove-delete-product-programmatically-in-magento-2/"
  - title: "How to Create Custom Order Status and State Programmatically in Magento 2?"
    url: "https://magecomp.com/blog/create-custom-order-status-state-programmatically-magento-2/"
---

# How to Login in to Magento 2 Admin without Password? (Using Root Script)

_Published: January 17, 2025_  
_Author: Dhiren Vasoya_  

![How to Login in to Magento 2 Admin without Password (Using Root Script)](https://magecomp.com/blog/wp-content/uploads/2025/01/How-to-Login-in-to-Magento-2-Admin-without-Password-Using-Root-Script-1024x512.webp)

**Hello Magento Friends,**

Today’s blog is on How to Login to Magento 2 Admin Dashboard with root script without password.

[![Hire Magento Developer CTA](https://magecomp.com/blog/wp-content/uploads/2023/03/Hire-Magento-Developer-1.webp)](https://magecomp.com/services/hire-magento-programmer/)There are times when you may lose access to your Magento 2 admin account due to a forgotten password or other technical issues. Luckily, Magento 2 allows you to log in to the admin panel without a password. This method uses a root script to create a new admin user or update an existing one so that you can regain access quickly.

> **[How to Reset Magento 2 Admin Password](https://magecomp.com/blog/reset-magento-2-admin-password/)**

Here’s a step-by-step guide to logging in to your Magento 2 admin without a password using a root script.

## Steps to Login in to Magento 2 Admin with Root Script:
**Step 1:** Create a file in your Magento root directory at the below path

**magento_root_directory\adminLoginscript.php**

Then add the code as follows

```
<?php
use MagentoFrameworkAppBootstrap;
require __DIR__ . '/../app/bootstrap.php';

/* code for dispaly error */
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

class adminLoginApp extends MagentoFrameworkAppHttp implements MagentoFrameworkAppInterface {

    public function launch()
    {
        $areaCode = 'adminhtml';
        $username = '{username}'; // admin user name '{username}'

        $this->_request->setPathInfo('/admin'); // magento admin path exam. example.com/admin
        $this->_state->setAreaCode($areaCode);
        $this->_objectManager->configure($this->_configLoader->load($areaCode));

        $user = $this->_objectManager->get('MagentoUserModelUser')->loadByUsername($username);
        $session = $this->_objectManager->get('MagentoBackendModelAuthSession');
        $session->setUser($user);
        $session->processLogin();

        if($session->isLoggedIn()) {

            $remoteAddress = $this->_objectManager->get('MagentoFrameworkHTTPPhpEnvironmentRemoteAddress');
            $adminSessionInfo = $this->_objectManager->create('MagentoSecurityModelAdminSessionInfo');
            $adminSessionInfo->setData('session_id', $session->getSessionId());
            $adminSessionInfo->setData('user_id', $user->getUserId());
            $adminSessionInfo->setData('ip', $remoteAddress->getRemoteAddress());
            $adminSessionInfo->setData('status', '1');
            $adminSessionInfo->save();

            $cookieManager = $this->_objectManager->get('MagentoFrameworkStdlibCookieManagerInterface');
            $cookieValue = $session->getSessionId();
            if ($cookieValue) {
                $sessionConfig = $this->_objectManager->get('MagentoBackendModelSessionAdminConfig');
                $cookiePath = str_replace('autologin.php', 'index.php', $sessionConfig->getCookiePath());

                $cookieMetadata = $this->_objectManager->get('MagentoFrameworkStdlibCookieCookieMetadataFactory')
                    ->createPublicCookieMetadata()
                    ->setDuration(3600)
                    ->setPath($cookiePath)
                    ->setDomain($sessionConfig->getCookieDomain())
                    ->setSecure($sessionConfig->getCookieSecure())
                    ->setHttpOnly($sessionConfig->getCookieHttpOnly());
                $cookieManager->setPublicCookie($session->getName(), $cookieValue, $cookieMetadata);
            }

            $backendUrl = $this->_objectManager->get('MagentoBackendModelUrlInterface');
            $path = $backendUrl->getStartupPageUrl();
            $url = $backendUrl->getUrl($path);
            $url = str_replace('adminLoginscript.php', 'index.php', $url); // here adminLoginscript.php script is file name
            header('Location: '.$url);
            exit;
        }
        return $this->_response;
    }
}

$bootstrap = Bootstrap::create(BP, $_SERVER);
$bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
/** @var MagentoFrameworkAppHttp $app */
$app = $bootstrap->createApplication('adminLoginApp');
$bootstrap->run($app);
```

**Step 2:** After the above step you will need to run the below-given URL

<https://yourdomain.com/adminLoginscript.php>

## Conclusion:
This is especially useful in emergency situations when you need instant access. But be sure to use this method responsibly and clean up the script after you’re done to maintain the security of your store.

Also read –

[**How to Set Password Reset Protection Type for Admin in Magento 2**](https://magecomp.com/blog/set-password-reset-protection-type-for-admin-in-magento-2/)

[**How to Disable Admin Password Expiration in Magento 2**](https://magecomp.com/blog/disable-admin-password-expiration-magento-2/)

If you have any security-related issues or problems with your Magento site, [**reach out to us**](https://magecomp.com/contact).

[![Magento-development-services](https://magecomp.com/blog/wp-content/uploads/2020/06/Hire-Magento-4-1024x284.webp)](https://magecomp.com/contact)**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/login-in-to-magento-2-admin-without-password-using-root-script/](https://magecomp.com/blog/login-in-to-magento-2-admin-without-password-using-root-script/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-18 09:44:06 UTC_  
