RobThree / TwoFactorAuth

PHP library for Two Factor Authentication (TFA / 2FA)
MIT License
1.08k stars 128 forks source link

How to migrate to new server #96

Closed Tsjippy closed 1 year ago

Tsjippy commented 1 year ago

I have migrated my website to a new server.

Now the 2fa verification always fails (verifyCode returns 0);

How can I find out why and how to solve it? I don't want all my users to set it up again....

What changed: Moved from php 7.4 to php 8.0.25 Moved from utf8 to utf8mb4 Moved to a different timezone

RobThree commented 1 year ago

99% sure the time on the server is off (or it's off on the previous one).

Tsjippy commented 1 year ago

Can I adjust the time in the database ? Or should I change the time on the server?

RobThree commented 1 year ago

I don't know what time in your database would be related to this? If you check the actual time on the server(s) you'll most likely see one of them is off.

Tsjippy commented 1 year ago

yes they are in different time zones: Server 1: Thu Dec 1 16:25:05 WAT 2022 Server 2: Thu Dec 1 08:25:04 MST 2022

RobThree commented 1 year ago

By default, this library uses time(), which, according to the PHP doc, returns a Unix Timestamp. which is UTC time (and TOTP uses UTC). So either you used a different timeprovider or your timezones aren't configured correctly.

Tsjippy commented 1 year ago

I have changed the timezones, now they are in the same timezone, still doesn't work

RobThree commented 1 year ago

Try ensureCorrectTime() (on both servers), see the docs.

If both are OK, please give the output of echo time() on both servers (from (roughly) the same time, no more than a few seconds apart) and share your $discrepancy value, if overridden.

willpower232 commented 1 year ago

in bash you can do date +"%s"

image

and then compare the output to https://time.is/Unix_time to confirm the values are the same or within a few seconds

Tsjippy commented 1 year ago

Thanks both for your replies! It works again

RobThree commented 1 year ago

Thanks both for your replies!

It works again

Please share with us what the issue was?

Tsjippy commented 1 year ago

I think it was a time issue. I changed the time zone and now it works ok