wstrange / GoogleAuth

Google Authenticator Server side code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to pass OTP starting with number 0

gokul656 opened this issue · comments

commented

If the authenticator code is like, 042345, while receive from API I can transfer it as String, but when I pass the value to authorize function it becames like authenticator.authorize(secret, 42345) . The preceding zero is removed. It'll be helpeful if the data type of code is String.

The authorize method signature takes an int. The TOTP RFC (https://www.rfc-editor.org/rfc/rfc6238) has a reference implementation illustrated where the code is treated as a base-10 integer. We may argue there are other encodings possible, but that choice was made with that rationale.

Convert the String to a base-10 integer. In Java there are even library method that will happily do that, even if your string has leading zeroes.