Magento2: Reset Admin 2FA (Two-Factor Authentication)

This article shows how you can reset your Magento 2 Admin User’s 2FA (Two-Factor Authentication).

Get your admin user ID from admin_user table.


SELECT user_id from admin_user WHERE username = 'YOUR_ADMIN_USERNAME';

OR,


SELECT user_id from admin_user WHERE email = 'YOUR_ADMIN_EMAIL';

For e.g. My admin user id = 299
username: MukeshChapagain

Check two-factor authentication related table data

The table name is msp_tfa_user_config.

MariaDB [magento]> SELECT * FROM msp_tfa_user_config WHERE user_id = 299 \G;

*************************** 1. row ***************************
msp_tfa_user_config_id: 272
user_id: 299
encoded_providers: []
encoded_config: 0:3:w/kFFwYoLPNsUT6eTgiUieF6xxxxxxxxzNwMiS/rlUJgvwuNEY0OeGCTtPItcvRrNxxxxxxxxxxeuKdKISV1oG3lNpVe/7cBmQlYxAm0ei6qJwuSYi+cSQKm2G0DnDySSQxxxxxxxsvtVNrspfOXYHUY2mW9mLgWhH4n8bN+q4xxxxxxx/xxxxxxxuBpz6S7DulbghahxeowZUm/COlNGklqA9B+RzNJTfKRxxxxxxxxxxxxxxxxxxxxrrKx8YNOAcYasKZJiiRf0oNe6QvZ/4p3JtuZTf4BjJ2qDCc4K3BuLp5ICjExxxxxxxxxxxHzPvPmaaFQ8/qiUufw==
default_provider: google
1 row in set (0.00 sec)

Reset 2FA for my user

bin/magento msp:security:tfa:reset –help
Description:
Reset configuration for one user

Usage:
msp:security:tfa:reset

Arguments:
user Username
provider Provider code

From the above query to msp_tfa_user_config table, I have figured out that my 2FA provider is google.

For my username MukeshChapagain, I will run the following CLI command to reset my 2FA:

bin/magento msp:security:tfa:reset MukeshChapagain google

AFTER RESET:

MariaDB [magento]> SELECT * FROM msp_tfa_user_config WHERE user_id = 299 \G;

*************************** 1. row ***************************
msp_tfa_user_config_id: 272
user_id: 299
encoded_providers: []
encoded_config: 0:3:DPNMxmjxxxxxxeyPbju+yhCwVFPxxxxxxxNaS5zPY
default_provider: google
1 row in set (0.00 sec)

Now, when you login to Magento admin, it will send you an email to set up 2FA so that you can re-setup 2FA.

Hope this helps. Thanks.