# Two factor auth consistently returns invalid authentication code

**URL:** https://meta.discourse.org/t/two-factor-auth-consistently-returns-invalid-authentication-code/84979
**Category:** Support
**Created:** [10 april 2018 om 13:53 UTC](https://meta.discourse.org/t/two-factor-auth-consistently-returns-invalid-authentication-code/84979 "2018-04-10T13:53:00Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![fero](https://avatars.discourse-cdn.com/v4/letter/f/b2d939/32.png) [@fero](https://meta.discourse.org/u/fero)
#### Post date: [10 april 2018 om 13:53 UTC](https://meta.discourse.org/t/two-factor-auth-consistently-returns-invalid-authentication-code/84979/1 "2018-04-10T13:53:00Z")

</div>

Hi,

I registered myself in a discussion forum that uses your system. I tried to set up 2 factor authentication there but it failed in the last step. When I entered back the code from my device it responded with error:

**Invalid authentication code**

Here on your forum I successfully enabled it. Do you know where might be a problem? I would then advise the administrators of that forum.

Thanks.

Cheers,  
Fero

---

<div class="post-metadata">

### Author: ![dax](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dax/32/244677_2.png) [@dax](https://meta.discourse.org/u/dax)
#### Post date: [10 april 2018 om 13:56 UTC](https://meta.discourse.org/t/two-factor-auth-consistently-returns-invalid-authentication-code/84979/2 "2018-04-10T13:56:56Z")

</div>

Is it possible to have a link to that site or is it private?

---

<div class="post-metadata">

### Author: ![fero](https://avatars.discourse-cdn.com/v4/letter/f/b2d939/32.png) [@fero](https://meta.discourse.org/u/fero)
#### Post date: [10 april 2018 om 14:38 UTC](https://meta.discourse.org/t/two-factor-auth-consistently-returns-invalid-authentication-code/84979/4 "2018-04-10T14:38:26Z")

</div>

[Link to the forum](https://platforma.slovensko.digital/). You can register there freely.

Thanks for any hint.

Cheers,  
Fero

---

<div class="post-metadata">

### Author: ![J5lx](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@J5lx](https://meta.discourse.org/u/J5lx)
#### Post date: [14 mei 2018 om 20:02 UTC](https://meta.discourse.org/t/two-factor-auth-consistently-returns-invalid-authentication-code/84979/5 "2018-05-14T20:02:53Z")

</div>

I recently had the same issue on a forum I host, and in the end I figured out that it occurred because my server time was slightly off. Try comparing the time of your server (including seconds) to network time (e.g. via [time.is](https://Time.is)), and if it’s different make sure that your system is configured to sync its clock across the network (using something like systemd-timesyncd or ntpd, if you’re on Linux). For me that did the trick.

---

<div class="post-metadata">

### Author: ![fero](https://avatars.discourse-cdn.com/v4/letter/f/b2d939/32.png) [@fero](https://meta.discourse.org/u/fero)
#### Post date: [15 mei 2018 om 12:23 UTC](https://meta.discourse.org/t/two-factor-auth-consistently-returns-invalid-authentication-code/84979/6 "2018-05-15T12:23:31Z")

</div>

Perfect, thanx Jacob. That was the root cause. It is fixed now. 🙂

Fero

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [15 mei 2018 om 23:08 UTC](https://meta.discourse.org/t/two-factor-auth-consistently-returns-invalid-authentication-code/84979/7 "2018-05-15T23:08:34Z")

</div>

@featheredtoast I was noticing that even being a few seconds off here causes things not to work.. can we add a bit more grace period for time slop?

---

<div class="post-metadata">

### Author: ![featheredtoast](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/featheredtoast/32/116994_2.png) [@featheredtoast](https://meta.discourse.org/u/featheredtoast)
#### Post date: [15 mei 2018 om 23:18 UTC](https://meta.discourse.org/t/two-factor-auth-consistently-returns-invalid-authentication-code/84979/8 "2018-05-15T23:18:22Z")

</div>

Sure thing - I’ve added a 30 second grace window that should alleviate this.  
[https://github.com/discourse/discourse/commit/74aecdfd9d93b8e2df4719c4140209dd38bb4ae0](https://github.com/discourse/discourse/commit/74aecdfd9d93b8e2df4719c4140209dd38bb4ae0)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [15 mei 2018 om 23:25 UTC](https://meta.discourse.org/t/two-factor-auth-consistently-returns-invalid-authentication-code/84979/9 "2018-05-15T23:25:12Z")

</div>

Wait .. reading the code, prior to this we had a ZERO second grace period? 😵

---

<div class="post-metadata">

### Author: ![featheredtoast](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/featheredtoast/32/116994_2.png) [@featheredtoast](https://meta.discourse.org/u/featheredtoast)
#### Post date: [15 mei 2018 om 23:28 UTC](https://meta.discourse.org/t/two-factor-auth-consistently-returns-invalid-authentication-code/84979/10 "2018-05-15T23:28:44Z")

</div>

The protocol comes with a 30 second window already, so it’s not as strict as it looks - This just adds a little more generosity.

---

<div class="post-metadata">

### Author: ![kirupa](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kirupa/32/374711_2.png) [@kirupa](https://meta.discourse.org/u/kirupa)
#### Post date: [14 juni 2018 om 04:26 UTC](https://meta.discourse.org/t/two-factor-auth-consistently-returns-invalid-authentication-code/84979/11 "2018-06-14T04:26:43Z")

</div>

I am having this same problem on my forums ([https://forum.kirupa.com/](https://forum.kirupa.com/)), and this used to work just fine. I have ensured the time is synchronized correctly as well. I think. Here is my Ubuntu time settings:

Local time: Thu 2018-06-14 00:24:04 EDT  
Universal time: Thu 2018-06-14 04:24:04 UTC  
RTC time: Thu 2018-06-14 04:23:14  
Timezone: America/New\_York (EDT, -0400)  
NTP enabled: yes  
NTP synchronized: yes  
RTC in local TZ: no  
DST active: yes  
Last DST change: DST began at  
Sun 2018-03-11 01:59:59 EST  
Sun 2018-03-11 03:00:00 EDT  
Next DST change: DST ends (the clock jumps one hour backwards) at  
Sun 2018-11-04 01:59:59 EDT  
Sun 2018-11-04 01:00:00 EST

If there isn’t an easy work around, is there any way to disable 2FA on my account via SSH’ing as root?

Thanks,  
Kirupa

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [14 juni 2018 om 04:28 UTC](https://meta.discourse.org/t/two-factor-auth-consistently-returns-invalid-authentication-code/84979/12 "2018-06-14T04:28:32Z")

</div>

Is your server time not set to UTC?

---

<div class="post-metadata">

### Author: ![kirupa](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kirupa/32/374711_2.png) [@kirupa](https://meta.discourse.org/u/kirupa)
#### Post date: [14 juni 2018 om 04:31 UTC](https://meta.discourse.org/t/two-factor-auth-consistently-returns-invalid-authentication-code/84979/13 "2018-06-14T04:31:07Z")

</div>

Bingo. That fixed it. Thanks for the help, Jeff! 🙂

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [8 juni 2024 om 12:37 UTC](https://meta.discourse.org/t/two-factor-auth-consistently-returns-invalid-authentication-code/84979/14 "2024-06-08T12:37:19Z")

</div>

This topic was automatically closed after 2250 days. New replies are no longer allowed.
