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. code:
json_data=request.get_json()
my_token=json_data['OTP']
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.
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