Unable to log in to Magento 2 how to fix

Basically, you were setting up your Magento 2.X store, fulfilled all the server requirements, added SSL, configured your Website, Store and Store View, installed extensions, and filled up the store configuration only to realize that suddenly you can't log in to the admin panel anymore.

There are no errors, nothing in the browser console, neither any problem with the browser Chrome / Firefox. You clear the sessions and cache to see it has no effect too. You search and find answers that keep pointing back to sessions and cache settings, but you did follow the documentation, and it still doesn't work.

Fast solution when unable to login

This configuration arrangement may or may not work, but still kindly attempt to use it as a starting point for solving the problem. After executing the steps, a manager will be able to obtain the option to log in.

Assuming that a manager was indeed unable to log in after this fix, the issue is in all likelihood unique in relation to these steps.

Pick Your Extensions

Free Installation

Free Support

The solution to the log in problem lies in manual database editing. If the server of the store has the phpMyAdmin tool for database access and editing installed, then the following must be executed by the manager:

  • Get access to the store MYSQL, MariaDB, or other solution used for database and open the table. Here is the table prefix that is set in some stores at the step of software installation.
  • Locate tab button, which,as is usually the case, is located in a particular part of the screen, that is, on the right side.
  • When the manager activates a search menu, he should look for the dropdown under the section. The dropdown may look as in which a should be inserted in the field next to it. Those were the actions necessary for launching the search for table rows with the "cookie" word in their path value.
  • When obtained the list of rows with delete the VALUE for some of the found rows, not all of the listed below rows may be present, so work with only those found:
web/cookie/cookie_domain
web/cookie/cookie_httponly
web/cookie/cookie_lifetime
web/cookie/cookie_path

That is it. Revive the administrator page with the F5 button and try signing in. It should work. Assuming it does, we should get to the core of the issue.

Fixing the core of the login problem

More often than not, following the store software's installation process, the value for the cookie domain is set as <.domain.com>. In this case, the software anticipates a sub-domain, however, the store name is put away as http://domain.com as its base URL. This problem can be fixed in two methods.

If there is no plan to use a subdomain for cookies, the cookie domain settings can be saved without a preceding period sign. In the admin panel, navigate to the Stores section. Locate the button for Configuration and then open the Web tab. In here, a field for Cookie Domain will be available. Set it as domain.com.

Assuming there is an intention to make a store future-prepared, including the permit for subdomain stockpiling of cookies, then the field should be set as .domain.com. Keep in mind that the domain name has a period mark at the beginning. In the store base URL ( Configuration -> Web -> Base URL>) add mark to the domain name. If the SSL is used, the last one should look like http://www.domain.com or https://www.domain.com.

Additionally, check other Cookie Settings: - Cookie Lifetime set to 86400 or leave the field blank to use the system value. - Cookie Path - Use HTTP Only set to Yes - Cookie Restriction Mode. Enable if a message for visitors consent for storing cookies should be displayed.

Additional tips that can help:

  • In table, find the path web/cookie/cookie_domain. And then check if that domain matches with the project's actual current domain. In case of a mismatch, simply change it. And then, after that, the admin login starts working.

  • Add or Update Web Url entries to https:// secure URLs for the below configuration entries in the database.

In Table set below value for your store:

web/unsecure/base_url => 'https://yoursiteurl.com/'
web/secure/base_url => 'https://yoursiteurl.com/'

Also, check cookie settings for the website; if in doubt, try to remove all cookie settings from table and login to admin. Afterward, the store manager can freely add proper cookie settings and obtain them from admin configurations.

  • If you are working in the local system and need to fix this issue urgently, please follow the below steps.

I know this is not a proper solution, but this is working fine in my local system.

Open file /vendor/magento/module-backend/Model/Auth/Session.php and comment these lines:

public function processLogin()
{
//  if ($this->getUser()) {
        $this->regenerateId();

        if ($this->_backendUrl->useSecretKey()) {
            $this->_backendUrl->renewSecretUrls();
        }

        $this->setIsFirstPageAfterLogin(true);
        $this->setAcl($this->_aclBuilder->getAcl());
        $this->setUpdatedAt(time());
//  }
    return $this;
}
Loading...