I am using Magento 2.4 community edition. Client has changed the admin user password and they forgot the new password so now they want to add the old password which was used earlier so how can i set?

6 Answers 6


In Magento 2.4, it is not possible to retrieve the old password of the admin user.

You can only reset it.


Magento 2 uses one-way hashing to encrypt passwords, which means that the original password cannot be decrypted from the hash value. Instead, when a user logs in, Magento 2 encrypts the entered password using the same algorithm and compares it to the stored hash value. If the two values match, the login attempt is successful.

Therefore, it is not possible to decrypt Magento 2 password hashes. If you need to change a user's password, the recommended way is to reset the password using the "Forgot Password" feature in the Magento 2 admin panel, or by using the bin/magento admin:user:create command-line tool to create a new user with a new password.

If you have access to the Magento 2 database and need to update a user's password hash, you can generate a new hash for the desired password using the password_hash() function in PHP, and update the corresponding record in the admin_user table with the new hash value. Here's an example:

Generate a new hash for the desired password using the password_hash() function:

$password = 'new_password';
$hash = password_hash($password, PASSWORD_DEFAULT);

Update the corresponding record in the admin_user table with the new hash value. You can use an SQL query or a database tool such as phpMyAdmin to make the change.

UPDATE `admin_user` SET `password` = '$hash' WHERE `username` = 'admin';

In this example, the admin user's password hash is updated with the new hash value generated by password_hash(). Note that changing the password hash directly in the database should only be done with caution and as a last resort, as it can lead to unexpected issues with user authentication.

Let me know if any query.



If you need to revert the admin user password in Magento 2, you can follow these steps:

  1. Log in to your Magento 2 admin panel.
  2. Go to the "System" tab in the main menu and select "All Users" under the "Permissions" section.
  3. Find the user whose password you want to revert and click on their row to edit their account.
  4. Scroll down to the "Account Information" section and click on the "Change Password" button.
  5. Leave the "New Password" and "Confirm Password" fields blank.
  6. Click on the "Save User" button.

You can reset the password. Simplest way is use the encripted value of md5(or sha256) to reset the password via SQL in database(This also applies to reset password for site users(customer entity)).

  1. First get the encripted value (following are use php to get the encrypted value)
  // get the encrypted value (password)
    $passwordText = 'Admin123';
    $password = md5($passwordText);
    //$password= hash('md5',$passwordText);
    echo $password.PHP_EOL;
  1. copy the encripted value of md5 in here, and execute the SQL. And then clean the cache. Admin user can login with password(Admin123).
# update the password of specified admin user.
update admin_user set password='{encrypted value of md5}::0' where username='{user_name}';

# update password of customer user.
update customer_entity set password_hash='{encrypted value of md5}::0' where email='{customer_email}';

About why use the way, please refer to following.

Magento password support multiple encriptions (please refer to the class to get detail \Magento\Framework\Encryption\Encryptor, and see the following screenshot.). enter image description here

enter image description here

SELECT * FROM `admin_user` WHERE `username` LIKE '%<user_name>%'

Take user_id from admin_user

SELECT * FROM `admin_passwords` WHERE `user_id` = <user_id>

Take password_hash from admin_passwords which 2nd last

UPDATE `admin_user` SET `password` = '<password_hash>' WHERE `admin_user`.`user_id` = <user_id>;

admin_user table has 'password' field. If we want to put old password so we can put 'password_hash' field from admin_passwords table into 'password' field of admin_user table.

admin_passwords tablet save old and new password keys in this 'password_hash' field.


I will not recommend to update value from database, you can reset the password through command line itself, you just need admin_username for that.

php bin/magento admin:user:create --admin-user=admin_username --admin-password=<new_password>

Above command will reset the password for admin_username user

  • It will reset the password but if someone forgot the password and he/she wants to use that password only than what is the best recommendation? Commented Mar 30, 2023 at 5:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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