One-Time Passwords (OTP) - Example
Last updated
Was this helpful?
Last updated
Was this helpful?
In this section, we shall provide an example of how to generate and validate One-Time Passwords (OTP) in Python. The Python library of our choice is , which implement the and standards. If you want to use this library you should follow the requirements in those standards. Installation:
We need to create a base32 secret which has to be shared between the authentication server and the client. We will use OTP model which produce a URI for an exchange, the secret and additional client-server details. It includes the shared secret, the client's username, and the issuer's name.
Run the above code example: .
Sample output:
Once the client stores the secret in a secure way, in a time-interval of a 30 seconds (by default) a new code will be generated.
Sample output:
Example validation check:
Output:
Run the above code example: .
You can install Google Authenticator from or and scan the QR code below:
Run the above code example: .