Authentication codes keep resetting
-
I set up my account for my site in Google Authenticator and it works for a while. After a while, an intermittent time period, the authentication codes stop working and I have to delete and recreate the account. This happens on multiple sites on which I use WP 2FA.
WP 6.7.1
PHP 8.2
WP 2FA 2.8.0
-
Thank you for using our plugin @jzilberberg
I am sorry to read about your issue. The most common cause for this is the time configuration. When the time is not synced / not correct on the server where the website is hosted, and the same on the device on which the authenticator app is installed, this happens.
It is very important to ensure that the time is correct on both devices. You can also confirm this without needing to uninstalling and reinstalling the plugin. The next time this happens you can:
- Use a 2FA backup code to log in
- Navigate to the user profile page
- Reset your 2FA config and configure it again
You will notice that even when reconfiguring it right away, it will not work. Most probably uninstalling and installing is working because in the process you might be doing something else that is syncing one of the device’s time.
I hope the above helps. Should you have any other questions, please do not hesitate to ask.
Thanks for the response! With regard to this, “When the time is not synced / not correct on the server where the website is hosted, and the same on the device on which the authenticator app is installed, this happens.”:
Are you saying the time has to be exactly the same? What about time zone differences? It seems like there would be no way to control this given users will most certainly be in different time zones.
And how else would the times not be synced?Hello @jzilberberg
No, the server and device where the app is installed do not have to be on the same timezone. However, they need to have the correct time of the configured timezone.
If you confirm the times are correct and the issue persists, let us know and we’ll dig deeper into this. My first question would be, do you have any other login / security plugins that are also interacting with the default WordPress login?
Also, what version of WordPress, PHP and the plugin are you running?
Looking forward to hearing from you.
Thanks!
I don’t understand this, “However, they need to have the correct time of the configured timezone.”. Can you please clarify? What is ‘they’? What has to have the correct time of the configured timezone? And which configured timezone are your referring to?
No other login/security plugins.
WP 6.7.1
PHP 8.2
WP 2FA 2.8.0
Thanks!In addition to my questions above:
– The server on which my site is hosted is in the central time zone.
– I am in the pacific time zone
– I have users that login in all different time zones.
– My Google Authenticator application does not have any configuration settings.
Given all this, wow am I supposed to configure things to make this work correctly?Hello again @jzilberberg,
My name is Lucian, and I’m part of the Melapress Support team. I’ll be assisting you moving forward.
Regarding your question: “However, they need to have the correct time of the configured timezone.” Can you please clarify?”
Here’s an example to illustrate:
- Suppose the server/site time at login is 4:02 PM.
- The time on your mobile device or laptop generator code app (where the 2FA codes are generated) is 4:03 PM.
Even a small time difference like this can cause authentication failures, as the encryption process relies on precise time synchronization. While the configured timezone does not affect this, the actual time must be correct and in sync across all devices involved in the 2FA process.
While this is the most common cause of such inconsistent problems (invalid 2FA codes), if you can confirm that all these components have the time in sync, we can then explore further causes of this unexpected behavior.I hope this helps and let me know if you need further clarification!
Thanks for your response. The time on my mobile device and laptop are being set automatically so there is no reason they should not be the same as the server. I can confirm that the times are in sync as I have viewed the server time and the times on my devices and they match.
I previously used a different 2FA plugin and never had this issue even once and nothing else has changed as far as time synchronization is concerned. I don’t use that one anymore because it stopped being supported.
So, any further assistance would be greatly appreciated!Hello again, @jzilberberg!
Thank you for confirming that!
Since everything we’ve checked so far suggests this is not a timing issue, let’s go back to your initial observation: “After a while, an intermittent time period, the authentication codes stop working.”
- Can you recall any specific actions that occur before the codes stop working?
For example, do you perform any site maintenance tasks, such as migrating the site between staging and production or applying updates?
Please note that if you are moving the website between environments (e.g., staging to production and vice versa), you must ensure that the encryption setup remains intact. This means keeping the plugin disabled during migration and ensuring encryption-related components are preserved.
You can find more details on this here: WP 2FA Migration Guide - If migration is not the cause, could you check if all 2FA methods are affected or only the authenticator app codes?
- As a quick test, try setting up a new user with both the Code via Email method and Backup Codes enabled.
- When/if the initial problem happens again with the OTP via app user, let’s see if this new user also encounters the issue when logging in with both methods.
This will help us determine if the issue is specific to the authenticator app or something broader.
Looking forward to your feedback!
Thanks!
No migration has been performed.
The only 2FA methods I have in place are from this plugin.
Regarding, “As a quick test, try setting up a new user with both the *Code via Email* method and *Backup Codes* enabled.”, I will do this, but since the issue is intermittent it may take days before the issue arises and I can check this. So, I will respond again when this happens.Hi @jzilberberg,
Thanks for the confirmation regarding the migration! Sure, keep me posted on your findings.
In the meantime, I’d recommend keeping a backup copy of the
wp_2faprefixed entries in thewp_usermetatable (at least for the user you’re testing with) and also the 2FA encryption key stored inwp-config.php. You can find more details on this in the article I shared earlier.If the issue reoccurs, check whether any of these values have changed. A change in either could break/reset the encryption which will render all codes invalid. If that’s the case, identifying what’s causing these changes to our plugin data, will surely pinpoint the culprit.
Looking forward to your updates!
Thanks for this. I have backed up the recommended items.
Just curious why in the wp-config.php file, in some cases, there would be these repeated lines for the WP 2FA encryption line:/** WP 2FA plugin data encryption key. For more information please visit melapress.com */
define( 'WP2FA_ENCRYPT_KEY', 'k4wwksqByqjw8tOcFrqb2w==' );
/** WP 2FA plugin data encryption key. For more information please visit melapress.com */
/** WP 2FA plugin data encryption key. For more information please visit melapress.com */
/** WP 2FA plugin data encryption key. For more information please visit melapress.com */
/** WP 2FA plugin data encryption key. For more information please visit melapress.com */
/** WP 2FA plugin data encryption key. For more information please visit melapress.com */
/** WP 2FA plugin data encryption key. For more information please visit melapress.com */
/** WP 2FA plugin data encryption key. For more information please visit melapress.com */
/** WP 2FA plugin data encryption key. For more information please visit melapress.com */
/** WP 2FA plugin data encryption key. For more information please visit melapress.com */
/** WP 2FA plugin data encryption key. For more information please visit melapress.com */
/** WP 2FA plugin data encryption key. For more information please visit melapress.com */
/** WP 2FA plugin data encryption key. For more information please visit melapress.com */
/** WP 2FA plugin data encryption key. For more information please visit melapress.com */
/** WP 2FA plugin data encryption key. For more information please visit melapress.com */
/** WP 2FA plugin data encryption key. For more information please visit melapress.com */
/** WP 2FA plugin data encryption key. For more information please visit melapress.com */
/** WP 2FA plugin data encryption key. For more information please visit melapress.com */
/** WP 2FA plugin data encryption key. For more information please visit melapress.com */
/** WP 2FA plugin data encryption key. For more information please visit melapress.com */
/** WP 2FA plugin data encryption key. For more information please visit melapress.com */
/** WP 2FA plugin data encryption key. For more information please visit melapress.com */
/** WP 2FA plugin data encryption key. For more information please visit melapress.com */
/** WP 2FA plugin data encryption key. For more information please visit melapress.com */
/** WP 2FA plugin data encryption key. For more information please visit melapress.com */Hi @jzilberberg,
Thanks for bringing this up!
We’re aware that in some cases, duplicate WP 2FA encryption key entries may appear in the
wp-config.phpfile. This typically happens when a site is migrated from staging to production (or vice versa) while the plugin is still active but there might be some other causes as well (it’s hard to pin point an exact cause, as we were never able to reproduce this constantly on our testing environments).Would you be able to recall when and how these duplicate lines appeared in your case? Understanding the exact conditions in which this occurs will help confirm if it’s the same situation we’ve encountered before.
That said, we already have an internal ticket for this, and we’ve made improvements to prevent this from happening in future updates, and while I cannot offer an exact estimate of the release date, that should be in the near future.
If there are any other questions, feel free to reach out!
Just to be clear, it is only the commented lines that are repeating. Not the define key line.
There was no migration involved that caused this. So I’m not sure how this happened.
Also, I am curious for dev and prod environments, can I modify the wp-config.php file as below and not have it overwritten by WP 2FA because it is in a conditional block and this is not what is normally recognized?if($_SERVER[‘HTTP_HOST’] == ‘milpitassmartcitydevwordpress.azurewebsites.net’) {
/** WP 2FA plugin data encryption key. For more information please visit melapress.com */
define( ‘WP2FA_ENCRYPT_KEY’, ‘[key value for dev]’ );
} else if($_SERVER[‘HTTP_HOST’] == ‘www.smartcitymilpitas.org’) {
/** WP 2FA plugin data encryption key. For more information please visit melapress.com */
define( ‘WP2FA_ENCRYPT_KEY’, ‘[key value for prod]’ );
}Hello again @jzilberberg!
Thank you for the clarification regarding the comments inside the
wp-config.phpfile.
That’s certainly unexpected, but you can safely remove them and monitor when (or if) they reappear, so we can investigate further if needed.Regarding your second question, we cannot provide support or recommendations for custom implementations like this. However, I would strongly advise against implementing this setup. The encryption key stored in
wp-config.phpis only one part of the encryption mechanism—WP 2FA also relies on encrypted user data stored in the database (usermetatable) which are generated based on the encrypt key found in the wp-config.php file.
Changing the key dynamically based on environment conditions can lead to complications, such as breaking the encryption, making 2FA data inaccessible, and potentially locking users out.If you need a setup that works across multiple environments, I would recommend ensuring that the encryption key (+wp_2fa usermeta values) remains consistent across dev and production rather than conditionally redefining it.
Of course, if it happens that you might find a workaround that works for you, feel free to share it here as it might help others who might experience a similar case.Let me know if you have any other questions!
The topic ‘Authentication codes keep resetting’ is closed to new replies.