Nik Nik - 1 year ago 116
Python Question

Python Flask app- leading zeros in TOTP error. (Python 2.7)

I have written a python flask application in which app generate totp for validation. (Python 2.7)

I use onetimepass library to validate totp against the application secret.

is_valid = otp.valid_totp(token=my_token, secret=my_secret)

However the issue i am facing is whenever a totp comes with leading zeroes it turns into an Octal number.
OTP is always treated as incorrect and user is unable to login.

How can i preserve these leading zeroes in such case? any code snippets or guidance will be of much help.

Nik Nik
Answer Source

Answer was simple as my_token was coming as string and i was converting it to a number. Adding this before converting to a number did the trick:

my_token.lstrip("0") #removes leading characters

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download