Git Product home page Git Product logo

otpy's Introduction

OTPy (One-Time Password for Python)

Introduction

This is a Python package to cater to all your needs for generating and verifying OTP (One-Time Password). You can use this package to enable 2FA (2-Factor Authentication) to safeguard your web applications.

The package currently only supports TOTP (Time-based One-Time Password) according to the specifications in RFC 6238 and will support HOTP (HMAC-based One-Time Password) which is based on RFC 4226 soon. The package will also add support for generating the QR code for key URI in future releases.

This is a server-side implementation of the TOTP. For the client-side, the user can use any authentication applications (e.g. Google Authenticator, Authy, etc.).

Installation

The package only supports Python 3.7 and above. To install:

pip install otpy

Alternatively,

python3 -m pip install otpy

To upgrade the package:

python3 -m pip install --no-cache-dir --upgrade otpy

Optionally, if you are Under unix, you can install the qrencode package:

apt-get install qrencode

To verify that you have successfully installed the package, you can try to run (You must have qrencode installed to run this):

python3 -m otpy

You will expect something like this:

Expected output

Usage

This package is very simple to use. First, import the package:

from otpy import OTPY

First, instantiate a TOTP object:

key = "0123456789ABCDEF" # Key string must be hexadecimal!
otp = OTPY(key)

To get the Base32 encoded key value that is specified in RFC 3548, simply run:

otp.get_base32_key()

This value is compatible with apps like Google Authenticator and can be used to generate key URI.

To get the TOTP value:

otp.get_totp()

Lastly, to verify if an OTP is correct, run:

otp.verify_otp("123456")

otpy's People

Contributors

l0rem1psum avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.