I am looking for a simple Perl implementation that verifies a Google authenticator token that has been created using a server side secret. For instance,
The following Google URL allows you to encode a server secret in base32 format (in the below case the secret is e4ytonjeim4hcsrhja5fe5kqfu) as a QR code that can be read from Google authenticator app (see image below):
https://chart.googleapis.com/chart?cht=qr&chs=100x100&chl=otpauth%3A%2F%2Ftotp%2Fmysite%3A29%3Fsecret%3De4ytonjeim4hcsrhja5fe5kqfu%26issuer%3Dmysite
Once the QR code is scanned into the authenticator app it produces tokens like: 716340. How do I verify the correctness of the token?
This question is the Perl equivalent of this Python question: Google Authenticator implementation in Python
Here's another solution, and you can verify it matches the tokens produced in this example
For posterity, I took the script from @Vijay's answer (thanks dude), simplified the algorithm a bit, added docs from TOTP definition, and added some sample code.
The number generation code I whittled down to which is just a simplification of @Vijay's answer:
The full TOTP 2 Factor Auth Perl script can be downloaded from Github.
Would Auth::GoogleAuthenticator work for your purposes?
Edit: sure it does; this validates the OTP as generated by the JS. When the counter isn't timely anymore it returns a empty string; i.e. false. And using the URL results in the app being synced to the JS:
Output:
Ok it took a little while but I've got a Perl solution (hopefully this makes up for the slightly lazy question :) Thanks to Borodin for his help with this (Taking the SHA1 HMAC of hex strings in Perl)