41

I tried to reset the admin password via Phpmyadmin in admin_user table but this doesn't seems to work. Also on chrome I am getting "This webpage has a redirect loop" error when loading admin page.

  • 1
    Regarding redirects, make sure that if you have xdebug enabled, then there is xdebug.max_nesting_level=200 in your php.ini. If it is not set, it is possible that you see admin login page (because nesting level is less than default 100 on that page), but when you enter credentials and try to login, dashboard cannot be rendered (nesting level is more than default 100 there). Also make sure to use some virtual host, not "localhost", to avoid issues with cookies. – Alex Paliarush Nov 20 '15 at 13:17
  • Dashboard icons / style were not loaded / rendered properly will this be due to xdebug ? Can you share how to setup xdebug on php.ini properly – Dev Nov 24 '15 at 13:27
  • Just add xdebug.max_nesting_level=200 to your php.ini config if you have XDebug enabled. – Alex Paliarush Nov 24 '15 at 13:41
  • this answer should help magento.stackexchange.com/a/137562/27907 and to generate the hashed password you can use xorbin.com/tools/sha256-hash-calculator – w.k Sep 22 '16 at 9:05
81

You can use Magento CLI to create new admin user with the following command, then you can go and change password of your original user.

<path_to_magento>/bin/magento admin:user:create --admin-user="admin" --admin-password="123123q" --admin-email="admin@example.com" --admin-firstname="Admin" --admin-lastname="Admin"
  • No other way without CLI? I tried to do that by installing Magerun on my machine (I am newbie to CLI). My command is like below, '<path_to_magento>php bin/magento admin:user:create [--admin-user="dave"] [--admin-password="admin123"] [--admin-email="admin1@localhost.com"] [--admin-firstname="dave"] [--admin-lastname="maritus"]' – Dev Nov 21 '15 at 4:50
  • 1
    Path to magento should go before "bin/magento", not before php. Also remove square brackets from actual command. – Alex Paliarush Nov 21 '15 at 7:53
  • Admin user created successfully, I used the details created to login dashboard but it doesn't works, stay on the same login page. – Dev Nov 21 '15 at 8:04
  • This is another problem, probably for separate question. Have you checked my comment about xdebug and localhost above? Also your session storage may be not writable and cause this. – Alex Paliarush Nov 21 '15 at 8:08
  • 4
    only god knows why they put square brackets there... – MagenX Nov 25 '15 at 9:26
26

Run below query to direct database.

An example is for reset password for admin user.

UPDATE admin_user SET `password` = SHA2('NewPassword', 256) WHERE `username`='admin';

NewPassword: Replace it with your password.

I hope it will work for you. Let me know if you any difficulty.

  • FYI; the CONCAT and salt is not needed. v. 2.1.7 – simonthesorcerer Nov 7 '17 at 9:02
  • Didn't work for Magento 2.3, needs salt, etc. – Qtax Feb 7 at 13:50
  • 1
    also, beware "lock_expires" field if you've repeated tried the same wrong password... – KolonUK Feb 12 at 12:45
13

There should be no equal signs or square brackets like this:

php bin/magento admin:user:create --admin-user mys_username --admin-password mypass123 --admin-email my@email.com --admin-firstname john --admin-lastname cage
  • This is the only one that worked for me – jfoutch Sep 1 '17 at 16:07
10

Run the following SQL queries to reset the admin password:

SET @salt = MD5(UNIX_TIMESTAMP());
UPDATE admin_user SET password = CONCAT(SHA2(CONCAT(@salt, 'MyNewPassword'), 256), ':', @salt, ':1') WHERE username = 'admin';
  • Was the only way I could get around the password requirements in Magento 2.3, to be able to set a simple admin password for development. n98-magerun2 3.0.4 didn't allow one to avoid the admin password requirements. – Qtax Feb 7 at 13:53
  • Worked in Magento 2.2.5, plus setting "lock_expires" to NULL – KolonUK Feb 12 at 12:36
9

There is a very nice tool out there called N98-Magerun

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:admin
Password:123456
Password successfully changed

Hope this helps.

  • Couldn't get this to run in my Bitnami test server - SQL was the only way to go for me. – KolonUK Feb 12 at 12:36
4

I hate remember long string bin/magento ...

Here is solution for anyone like touching:

put this code in pub/index.php

\Magento\Framework\App\ObjectManager::getInstance()->get("\Magento\Framework\Encryption\Encryptor")->getHash("yourpass");

Look at the footer of anypage: enter image description here

Copy that code and go to phpmyadmin:

update admin_user set password = '<code above>' where username='admin';

BTW. This is reset password question if you use admin:user:create it do reset or create but Uhm... Not exactly.

  • 2
    This would not really be safe to do in a publicly open website... You could also download n98-magerun2 and run n98-magerun2.phar dev:console and execute the code there: $di->get("\Magento\Framework\Encryption\Encryptor")->getHash("yourpass"); or just use n98-magerun2.phar admin:user:change-password – 7ochem May 18 '17 at 10:54
2

Referring to answer of Alex it works with a little modification. You have to navigate into the folder of M2 install, then run the code below:

php bin/magento admin:user:create --admin-user=admin --admin-password=admin123 --admin-email=admin@magento.tld --admin-firstname=admin --admin-lastname=admin

You don't need / before the bin folder, but you need php command before the whole "sentence".

The pass generation worked for me, but the admin page was'nt logged me in:/

0
 1. login to magento 2 admin.
 2. Go to system > All Users.
 3. Select your User
 4. reset password from 'User Info' > 'Account Information'
  • I have edited my question. what If we do when lost a password. – Dev Nov 20 '15 at 12:37
0

Just open your database access and hit the below query

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.