cancel
Showing results for 
Search instead for 
Did you mean: 

Can't log in to Magento admin

SOLVED

Can't log in to Magento admin

I have some issue with login to my admin panel. When i try to use forgot password, i dont get any email. How do i reset password, or find my old one? I am using chrome, and i use the password that is saved in there on the password list but i think i may have changed the password and not saved it. Any one?

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Can't log in to Magento admin

Hello @rmoen,

 

I have also updated previous comment, If you have ssh access then please do following things to easy to chagne password.

Basically, you directly download it to the root of your Magento project

wget https://files.magerun.net/n98-magerun2.phar

Next set executable permissions (for UNIX users only)

chmod +x ./n98-magerun2.phar

Now when you run

php n98-magerun2.phar

You will get a list of all available commands offered by the tool.

Now for resetting a forgotten admin user password first we need to get the username of the admin user, to get that we can run

php n98-magerun2.phar admin:user:list

This will provide you a list all the available admin user, the output will look something like

+----+-----------------+-------------------------------+--------+
| id | username        | email                         | status |
+----+-----------------+-------------------------------+--------+
| 1  | admin           | admin@example.com             | active |
| 2  | nextadmin       | nextadmin@example.com         | active |
+----+-----------------+-------------------------------+--------+

Now to reset the password we do

php n98-magerun2.phar admin:user:change-password

You will be prompted for the username of the admin user and new password for that user.

Username:adminPassword:123456
Password successfully changed

 

--

If my answer is useful, please Accept as Solution & give Kudos

View solution in original post

7 REPLIES 7

Re: Can't log in to Magento admin

Hello @rmoen ,

 

You can reset other 2 way to reset your password

 

Solution 1: Reset Magento 2 admin password in phpmyadmin
Go to phpmyadmin and copy the following sql query:

UPDATE admin_user SET password = CONCAT(SHA2('xxxxxxxYourNewPassword', 256), ':xxxxxxx:1') WHERE username = 'admin';

The xxxxxxx character sequence is a cryptographic salt, it is saved in app\etc\env.php file

<?php
return array (
  ...
  'crypt' => 
  array (
    'key' => '525701df74e6cba74d5e9a1bb3d935ad', //cryptographic salt
  ),
  ...


Solution 2: Reset Magento 2 admin password via command line (cli)
We typed on Magento 2 root folder:

php bin/magento -h

It show the admin command line:

...
admin
admin:user:create Creates an administrator
admin:user:unlock Unlock Admin Account
...


Magento 2 does not support reset password via command line. However, we can create a new admin account, then use the new account to reset the old one.

php bin/magento admin:user:create --admin-user='new-admin' --admin-password='!admin123!' --admin-email='info@domain.com' --admin-firstname='Jon' --admin-lastname='Doe'

--
If my answer is useful, please Accept as Solution & give Kudos

Re: Can't log in to Magento admin

is xxxxxxxx in front of YourNewPassword the cryptographic salt? or am i only set my new password there? 

I get unexpected token when i paste the key from env.php

And CONCAT , SHA2 does not exist if i write it in the sql query.

I have never done this before, sorry Smiley Happy

 

 

Re: Can't log in to Magento admin

Hello @rmoen ,

 

 

UPDATE admin_user SET `password` = CONCAT(SHA2('xxxxxxxxNewPassword', 256), ':xxxxxxxx:1') WHERE `username` = 'admin';

 

  • This command assumes that you want to change the password for the admin user account. To change the password for another account, change the username field to the correct value.
  • The xxxxxxxx character sequence is a cryptographic salt. It can be anything you want (and any length you want), but make sure you use the same value in both parts of the SQL statement.

 

 

--
If my answer is useful, please Accept as Solution & give Kudos

Re: Can't log in to Magento admin

#1064 - Something is wrong in your syntax near 'Smiley Surprisedoeeh9nzrdob8q1n9esmjbtvcidsebmu:1) WHERE username = 'runemoen'' on line 1

And i get a lot of errors.

14 errors were found during analysis.


Unrecognized keyword. (near "SET PASSWORD" at position 18)
Unexpected token. (near "=" at position 31)
Unrecognized keyword. (near "CONCAT" at position 33)
Unexpected token. (near "(" at position 39)
Unrecognized keyword. (near "SHA2" at position 40)
Unexpected token. (near "(" at position 44)
Unexpected token. (near "Tref98gh" at position 45)
Unexpected token. (near "," at position 53)
Unexpected token. (near "256" at position 55)
Unexpected token. (near ")" at position 58)
Unexpected token. (near "," at position 59)
Unexpected token. (near "Smiley Surprisedoeeh9nzrdob8q1n9esmjbtvcidsebmu" at position 61)
Unexpected token. (near ":1" at position 94)
Unexpected token. (near ")" at position 96)

Re: Can't log in to Magento admin

Hello @rmoen 

 

I would suggest you to run below SQL query either from the Phpmyadmin or from the command line tool :

 

SET @salt = MD5(UNIX_TIMESTAMP());
UPDATE admin_user SET password = CONCAT(SHA2(CONCAT(@salt, 'YourNewPassword'), 256), ':', @salt, ':1') WHERE username = 'admin';

Then clear the cache and check it might work !

 

Let me know if you still face the issue - after running this query !

 

if issue solved,Click Kudos & Accept as Solution

Re: Can't log in to Magento admin

Hello @rmoen,

 

I have also updated previous comment, If you have ssh access then please do following things to easy to chagne password.

Basically, you directly download it to the root of your Magento project

wget https://files.magerun.net/n98-magerun2.phar

Next set executable permissions (for UNIX users only)

chmod +x ./n98-magerun2.phar

Now when you run

php n98-magerun2.phar

You will get a list of all available commands offered by the tool.

Now for resetting a forgotten admin user password first we need to get the username of the admin user, to get that we can run

php n98-magerun2.phar admin:user:list

This will provide you a list all the available admin user, the output will look something like

+----+-----------------+-------------------------------+--------+
| id | username        | email                         | status |
+----+-----------------+-------------------------------+--------+
| 1  | admin           | admin@example.com             | active |
| 2  | nextadmin       | nextadmin@example.com         | active |
+----+-----------------+-------------------------------+--------+

Now to reset the password we do

php n98-magerun2.phar admin:user:change-password

You will be prompted for the username of the admin user and new password for that user.

Username:adminPassword:123456
Password successfully changed

 

--

If my answer is useful, please Accept as Solution & give Kudos

Re: Can't log in to Magento admin

Thanks alot. Worked as a charm.