mirror of
https://github.com/antonioribeiro/google2fa.git
synced 2026-04-26 16:45:49 +03:00
[GH-ISSUE #129] verifyKey will always return false #295
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/google2fa#295
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @pixagraphic on GitHub (Oct 16, 2019).
Original GitHub issue: https://github.com/antonioribeiro/google2fa/issues/129
I'm using it exactly as instructed, but the generated codes will not be validated:
When I register a user, a secret key is created and stored to the database:
The inlineUrl is returned to the user and the qr-code is displayed.
On login I check the user provided code:
But this will always return false...
@pixagraphic commented on GitHub (Oct 16, 2019):
Maybe this helps someone else: the problem was the "$google2fa->setAlgorithm(Constants::SHA512);" part. The algorithm should only be set during key generation (registration). When verifying the key the algorithm must not be set. When I removed the setAlgorithm from there everything works fine. Thanks for this library!
@bengearig commented on GitHub (Mar 11, 2021):
@pixagraphic You're actually using SHA1 and not SHA512. This didn't sit right with me when I had this issue so I investigated further.
The Microsoft Authenticator app ignores the algorithm setting in the otpauth:// url encoded in the QR code and instead uses SHA1 without any warning or indication of this fallback. The Google Authenticator app on the other hand will respect the SHA512 setting.
I am not sure which app you are using, but I wanted to point this out to you and anyone else that ends up here that your issue is likely related to the authenticator application you are using and not your code. Do not remove the code to set the algorithm as you will end up with SHA1 when you were expecting SHA512.
@pixagraphic commented on GitHub (Mar 11, 2021):
Hey, thanks for pointing that out. I think you're right that it's an issue with the authenticator applications as it worked with some devices but didn't with others.
In the end I went with SHA1 for optimal compatibility as SHA1 is only being used as hash function for the HMAC computation and therefor may still be assumed secure especially for my purpose. [1]
[1] https://cseweb.ucsd.edu/~mihir/papers/hmac-new.html