To get back into WordPress after losing your 2FA device, work down this list: (1) type a saved backup code into the 2FA code field, (2) ask another administrator to turn off 2FA on your profile, (3) on GuardPress, add define( 'GUARDPRESS_2FA_DISABLED', true ); to wp-config.php, (4) delete your 2FA record in the database (the table depends on the plugin), or (5) deactivate the 2FA plugin by renaming its folder in wp-content/plugins/. Methods 3 and 5 take about a minute if you can reach your site's files.
You enabled two-factor authentication on your WordPress site, the single best thing you can do to prevent unauthorized logins. Then your phone broke, you switched devices, or you accidentally deleted your authenticator app. Now you're staring at a 2FA prompt with no way to generate a valid code.
This is one of the most common WordPress lockout scenarios, and it's almost always recoverable. The key is knowing which recovery method to try first and in what order.
This guide covers five recovery methods, from typing a backup code to editing the database, with the exact steps for GuardPress, Wordfence, the Two Factor plugin and WP 2FA.
Why You're Locked Out of WordPress 2FA
Two-factor authentication uses time-based one-time passwords (TOTP) that are generated by an authenticator app on your device. The app and your server share a secret key, and both use the current time to calculate matching 6-digit codes every 30 seconds.
When that chain breaks, you lose access. The most common causes:
- Lost or broken phone: your authenticator app was on a device you no longer have
- Deleted authenticator app: accidentally removed without backing up your accounts
- New phone without transfer: upgraded devices and didn't migrate your authenticator data
- App data corrupted: authenticator reset itself after an OS update or restore
- Time sync issues: codes are rejected because your device clock is off by more than 30 seconds
If your codes are being rejected but you still have the authenticator app, the issue might be clock drift. Check the time sync fix at the bottom of this article before trying the recovery methods.
Method 1: Use Your Backup Recovery Codes
This is the fastest recovery method and the one you should always try first. When you set up 2FA, your security plugin gave you a set of one-time backup codes (GuardPress generates 10). If you saved them, you're 30 seconds away from being back in.
- Go to your WordPress login page and enter your username and password as normal
- On the 2FA prompt, enter one of your backup codes instead of the 6-digit app code. In GuardPress the backup code goes into the same Two-Factor Authentication Code field; some other plugins show a separate backup-code link on the prompt
- Each code works once, so cross it off after you use it
- Once logged in, open your profile, pair your new device and generate a fresh set of codes
Check your password manager (1Password, Bitwarden, LastPass), secure notes app, any printed backup you stored in a safe place, or your email (you may have sent them to yourself). GuardPress Pro shows the codes once during setup and won't let you finish until you confirm you've saved them.
Method 2: Ask Another Administrator
If you didn't save your recovery codes but there's another admin who can sign in, this is the next easiest fix. They can turn off 2FA on your account from your profile, with no technical steps.
- Have the other administrator log into the WordPress dashboard
- Navigate to Users → All Users and click "Edit" on your profile
- Scroll to the Two-Factor Authentication section and turn it off. In GuardPress the button is Disable Two-Factor Authentication, and WordPress asks the admin to confirm with their own password
- Log in with just your password and set up 2FA again on your current device
WP 2FA's own documentation recommends this as the first step too. It's why every WordPress site should have at least two administrator accounts.
Method 3: Turn Off GuardPress 2FA From wp-config.php
If you use GuardPress and can reach your site's files, this is the cleanest fix: one line in wp-config.php switches off the 2FA check while you sign in, and the rest of GuardPress (firewall, login limits, scanning) keeps running.
- Open
wp-config.phpin your host's file manager or over SFTP. It sits in your site's root folder, next towp-content - Add this line above the line that says
/* That's all, stop editing! */:define( 'GUARDPRESS_2FA_DISABLED', true ); - Sign in with your username and password. No 2FA prompt appears
- Go to your profile, disable and re-enable 2FA to pair your new device, and save the new backup codes
- Delete the line from
wp-config.phpso 2FA is enforced again
While the constant is set, no account on the site is asked for a 2FA code. Treat it as a two-minute switch, not a setting.
Method 4: Remove Your 2FA Record in the Database
If you're the only admin and didn't save recovery codes, you can delete your 2FA record directly. Each plugin stores it in a different place, so pick the query for the plugin you use.
Step 1: Open phpMyAdmin (or WP-CLI)
Log into your hosting control panel (cPanel, Plesk, or your host's dashboard) and open phpMyAdmin. Most hosts have a direct link in their database section. If you have SSH, you can run the same queries with wp db query.
Step 2: Find Your User ID
Run this query to find your WordPress user ID:
SELECT ID, user_login FROM wp_users
WHERE user_login = 'your_username';
Step 3: Delete Your 2FA Record
Replace 123 with your user ID from Step 2 and run the query for your plugin:
| Plugin | Where it stores 2FA | Query |
|---|---|---|
| GuardPress | wp_gp_two_factor table | DELETE FROM wp_gp_two_factor WHERE user_id = 123; |
| Wordfence Login Security | wp_wfls_2fa_secrets table | DELETE FROM wp_wfls_2fa_secrets WHERE user_id = 123; |
| Two Factor (WordPress.org plugin) | user meta | DELETE FROM wp_usermeta WHERE user_id = 123 AND meta_key IN ('_two_factor_enabled_providers', '_two_factor_provider'); |
With WP-CLI the GuardPress version is wp db query "DELETE FROM wp_gp_two_factor WHERE user_id = 123;", and for the Two Factor plugin wp user meta delete 123 _two_factor_enabled_providers. For WP 2FA and other plugins, use Method 2 or Method 5, as WP 2FA's own documentation does.
Step 4: Log In and Reconfigure
2FA is now off for your account. Log in with just your password and set 2FA up again. If your site requires 2FA for your role, the plugin will ask you to set it up as you sign in. Save your recovery codes this time.
The queries above use the default wp_ table prefix. If your site uses a custom prefix, check wp-config.php for the $table_prefix value and adjust the table names. Take a database backup before running any DELETE.
Method 5: Temporarily Disable the Plugin via FTP
If you can't use any of the methods above, deactivate the whole 2FA or security plugin by renaming its folder. This removes 2FA enforcement completely until you rename it back.
- Connect via FTP/SFTP: use FileZilla, your hosting's file manager, or any SFTP client
- Navigate to
/wp-content/plugins/and find the plugin's folder:guardpressfor GuardPress,wordfencefor Wordfence,two-factorfor Two Factor,wp-2fafor WP 2FA - Rename the folder: for example, change
guardpresstoguardpress-disabled. WordPress deactivates the plugin automatically - Log into WordPress: with the plugin disabled, 2FA is not enforced
- Rename the folder back to its original name, reactivate the plugin in the dashboard, and reconfigure 2FA with recovery codes properly saved
With SSH access, wp plugin deactivate guardpress (or the plugin's folder name) does the same in one command.
While the security plugin is disabled, your site loses all its protections (firewall, login limiting, malware scanning, etc.). Complete this process as quickly as possible and re-enable the plugin immediately after reconfiguring 2FA.
Fixing Time Sync Issues (Codes Rejected)
If you still have your authenticator app but codes keep getting rejected, the problem is almost certainly clock drift. TOTP codes are time-sensitive. If your device clock is off by even 30-60 seconds, every code will be invalid.
- Enable automatic time: on your phone, go to Settings → Date & Time and enable "Set automatically"
- Google Authenticator (Android): open the app, tap the three-dot menu, go to Settings → Time correction for codes → Sync now
- Server time: contact your host to verify the server's NTP synchronization is working correctly
- Try adjacent codes: the code changes every 30 seconds, so try the code immediately before or after it transitions
How to Prevent Future 2FA Lockouts
Getting locked out once is a learning experience. Getting locked out twice is a process failure. Set up these safeguards now:
- Save recovery codes in a password manager: 1Password, Bitwarden, and LastPass all have secure notes features perfect for this
- Use a cloud-synced authenticator: Authy, 1Password, and Microsoft Authenticator can sync your 2FA accounts across multiple devices, so losing one phone doesn't lock you out
- Set up 2FA on a second device: scan the QR code on both your phone and a tablet during initial setup
- Save the QR code securely: screenshot the setup QR code and store it in encrypted storage (not your camera roll)
- Maintain a second admin account: a separate administrator with independent 2FA gives you a backdoor without compromising security
- Verify your site after recovery: run our free Security Scanner to confirm nothing was tampered with while your plugin was disabled
Authy: cloud backup and multi-device sync (our top recommendation). 1Password: stores 2FA tokens alongside your passwords. Microsoft Authenticator: cloud backup option with enterprise features.