All Projects → pyauth → pyotp

pyauth / pyotp

Licence: other
Python One-Time Password Library

Programming Languages

139335 projects - #7 most used programming language
30231 projects

Projects that are alternatives of or similar to pyotp

One Time
One Time Password (TOTP and HOTP) library for Clojure. TOTP/HOTP is widely used for Two Factor / Multi Factor Authentication.
Stars: ✭ 129 (-93.32%)
Mutual labels:  totp, hotp, mfa, 2fa
📱 Two-Factor Authentication (2FA) client for Android + Wear OS
Stars: ✭ 155 (-91.97%)
Mutual labels:  totp, hotp, 2fa
A Web app to manage your Two-Factor Authentication (2FA) accounts and generate their security codes
Stars: ✭ 664 (-65.6%)
Mutual labels:  totp, hotp, 2fa
Go Guardian
Go-Guardian is a golang library that provides a simple, clean, and idiomatic way to create powerful modern API and web authentication.
Stars: ✭ 204 (-89.43%)
Mutual labels:  totp, hotp, 2fa
Minimal TOTP generator in 20 lines of Python
Stars: ✭ 678 (-64.87%)
Mutual labels:  totp, hotp, 2fa
A Swift library for generating One Time Passwords (OTP)
Stars: ✭ 119 (-93.83%)
Mutual labels:  totp, hotp, 2fa
A free, secure and open source app for Android to manage your 2-step verification tokens.
Stars: ✭ 2,692 (+39.48%)
Mutual labels:  totp, hotp, 2fa
CrOTP - One Time Passwords for Crystal
Stars: ✭ 62 (-96.79%)
Mutual labels:  totp, hotp, 2fa
🔑 A small library for generating TOTP and HOTP one-time passwords on iOS.
Stars: ✭ 243 (-87.41%)
Mutual labels:  totp, hotp, 2fa
Enhanced fork of FreeOTP-Android providing a feature-rich 2FA authenticator
Stars: ✭ 223 (-88.45%)
Mutual labels:  totp, hotp, 2fa
The Single Sign-On Multi-Factor portal for web apps
Stars: ✭ 11,094 (+474.82%)
Mutual labels:  totp, mfa, 2fa
A small and easy-to-use one-time password generator library for Java according to RFC 4226 (HOTP) and RFC 6238 (TOTP).
Stars: ✭ 107 (-94.46%)
Mutual labels:  totp, hotp, 2fa
Java Otp
A one-time password (HOTP/TOTP) library for Java
Stars: ✭ 265 (-86.27%)
Mutual labels:  totp, hotp, 2fa
A ready-to-launch User and Authentication system for those that don't want to build it
Stars: ✭ 324 (-83.21%)
Mutual labels:  totp, mfa, 2fa
**NOT MAINTAINED** Two-factor authentication for Node.js. One-time passcode generator (HOTP/TOTP) with support for Google Authenticator.
Stars: ✭ 2,531 (+31.14%)
Mutual labels:  totp, hotp, mfa
A highly configurable yet simple to use TOTP based two-factor authentication processing module for SimpleSAMLphp.
Stars: ✭ 16 (-99.17%)
Mutual labels:  totp, mfa, 2fa
apache 2fa
Apache two-factor (2FA) authentication with Google Authenticator based on Time-based One-Time Password (TOTP) or HMAC-based one-time password (HOTP) Algorithms.
Stars: ✭ 63 (-96.74%)
Mutual labels:  totp, hotp, 2fa
Random tools I've written to make life easier using AWS, namely aws-choose-profile and aws-mfa-login
Stars: ✭ 46 (-97.62%)
Mutual labels:  mfa, 2fa
HMAC-based (HOTP) and Time-based (TOTP) One-Time Password manager. Works with Google Authenticator for Two-Factor Authentication.
Stars: ✭ 79 (-95.91%)
Mutual labels:  totp, hotp
 Copy 2FA tokens in a click (macOS)
Stars: ✭ 13 (-99.33%)
Mutual labels:  totp, 2fa

PyOTP - The Python One-Time Password Library

PyOTP is a Python library for generating and verifying one-time passwords. It can be used to implement two-factor (2FA) or multi-factor (MFA) authentication methods in web applications and in other systems that require users to log in.

Open MFA standards are defined in RFC 4226 (HOTP: An HMAC-Based One-Time Password Algorithm) and in RFC 6238 (TOTP: Time-Based One-Time Password Algorithm). PyOTP implements server-side support for both of these standards. Client-side support can be enabled by sending authentication codes to users over SMS or email (HOTP) or, for TOTP, by instructing users to use Google Authenticator, Authy, or another compatible app. Users can set up auth tokens in their apps easily by using their phone camera to scan otpauth:// QR codes provided by PyOTP.

Implementers should read and follow the HOTP security requirements and TOTP security considerations sections of the relevant RFCs. At minimum, application implementers should follow this checklist:

  • Ensure transport confidentiality by using HTTPS
  • Ensure HOTP/TOTP secret confidentiality by storing secrets in a controlled access database
  • Deny replay attacks by rejecting one-time passwords that have been used by the client (this requires storing the most recently authenticated timestamp, OTP, or hash of the OTP in your database, and rejecting the OTP when a match is seen)
  • Throttle (rate limit) brute-force attacks against your application's login functionality
  • When implementing a "greenfield" application, consider supporting FIDO U2F/WebAuthn in addition to HOTP/TOTP. U2F uses asymmetric cryptography to avoid using a shared secret design, which strengthens your MFA solution against server-side attacks. Hardware U2F also sequesters the client secret in a dedicated single-purpose device, which strengthens your clients against client-side attacks. And by automating scoping of credentials to relying party IDs (application origin/domain names), U2F adds protection against phishing attacks. One implementation of FIDO U2F/WebAuthn is PyOTP's sister project, PyWARP.

We also recommend that implementers read the OWASP Authentication Cheat Sheet and NIST SP 800-63-3: Digital Authentication Guideline for a high level overview of authentication best practices.

Quick overview of using One Time Passwords on your phone

  • OTPs involve a shared secret, stored both on the phone and the server
  • OTPs can be generated on a phone without internet connectivity
  • OTPs should always be used as a second factor of authentication (if your phone is lost, you account is still secured with a password)
  • Google Authenticator and other OTP client apps allow you to store multiple OTP secrets and provision those using a QR Code


pip install pyotp


Time-based OTPs

totp = pyotp.TOTP('base32secret3232') # => '492039'

# OTP verified for current time
totp.verify('492039') # => True
totp.verify('492039') # => False

Counter-based OTPs

hotp = pyotp.HOTP('base32secret3232') # => '260182' # => '055283' # => '316439'

# OTP verified with a counter
hotp.verify('316439', 1401) # => True
hotp.verify('316439', 1402) # => False

Generating a Secret Key

A helper function is provided to generate a 32-character base32 secret, compatible with Google Authenticator and other OTP apps:


Some applications want the secret key to be formatted as a hex-encoded string:

pyotp.random_hex()  # returns a 40-character hex-encoded secret

Google Authenticator Compatible

PyOTP works with the Google Authenticator iPhone and Android app, as well as other OTP apps like Authy. PyOTP includes the ability to generate provisioning URIs for use with the QR Code scanner built into these MFA client apps:

pyotp.totp.TOTP('JBSWY3DPEHPK3PXP').provisioning_uri(name='[email protected]', issuer_name='Secure App')

>>> 'otpauth://totp/'

pyotp.hotp.HOTP('JBSWY3DPEHPK3PXP').provisioning_uri(name="[email protected]", issuer_name="Secure App", initial_count=0)

>>> 'otpauth://hotp/'

This URL can then be rendered as a QR Code (for example, using which can then be scanned and added to the users list of OTP credentials.

Parsing these URLs is also supported:


>>> <pyotp.totp.TOTP object at 0xFFFFFFFF>


>>> <pyotp.totp.HOTP object at 0xFFFFFFFF>

Working example

Scan the following barcode with your phone's OTP app (e.g. Google Authenticator):

Now run the following and compare the output:

import pyotp
totp = pyotp.TOTP("JBSWY3DPEHPK3PXP")
print("Current OTP:",


For new applications:
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].