3

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.

Steve Vinoski
  • 19,847
  • 3
  • 31
  • 46
Nik
  • 431
  • 1
  • 6
  • 10
  • isn't the token always a number? (whilst the magic is not) – tuergeist Sep 26 '16 at 06:12
  • Its always a number but leading zeroes make it into a octal number. See : http://stackoverflow.com/a/1548437/4651101 – Nik Sep 26 '16 at 06:27
  • I know, it's common. What I wanted to say is, that you should not have non-decimal numbers here. Feed in decimal once, there is no leading 0 and it shall work (at least it does for me) – tuergeist Sep 26 '16 at 13:17

1 Answers1

0

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

Nik
  • 431
  • 1
  • 6
  • 10