Coder Social home page Coder Social logo

nogoodusername / simple-otp Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 3.0 192 KB

Simple OTP Generation and Verification Library that does not use any Database or Cache

License: MIT License

Makefile 18.15% Python 81.85%
python python3 python-package otp otp-verification otp-generator

simple-otp's Introduction

simple-otp

A simple OTP Generation and Verification Library which works without a Database or Cache.

PyPI version

Features

  • Does not require database or cache
  • Easy to implement
  • Has OTP expiry function

How to use this?

Usage explained in diagram below

how-to-use

Installation

pip install -U simple-otp

Usage Example

import os
from time import sleep
from simpleotp import OTP

SECRET_KEY = os.getenv('SECRET')

otp_handler = OTP(SECRET_KEY,
                  length=6,
                  expires_after=2,
                  user_identifier='[email protected]')

# generate OTP - returns OTP and hash
otp, sig = otp_handler.generate()
print(otp, sig)

# verify OTP - correct OTP and hash passed to verify method
is_verified = otp_handler.verify(otp, sig)
print(is_verified) # returns True

# verify OTP - incorrect hardcoded OTP passed to verify method 
is_verified = otp_handler.verify('123', sig)
print(is_verified) # returns False

# Sleep added to simulate Expiry of OTP
sleep(2 * 61)
# Correct OTP and hash passed to verify method
# But after expiry time has passed
is_verified = otp_handler.verify(otp, sig)
print(is_verified) # returns False

The library also includes helper method to generate a random secret key

from simpleotp import generate_secret

SECRET_KEY = generate_secret()
print(SECRET_KEY) # 'Q0CZYBRDECESA72M'

Build Requirements

  • Make
  • Python
  • Twine

Initialise Build Environment

One time initialisation

make init

Make a release build

  1. Ensure that working directory is clean and all files are commited.
  2. Bump the version. Please read Semantic Version 2.0.0 before bumping versions.
    make release PART=[major/minor/patch]
    
  3. Update the CHANGELOG.md.
  4. Push release tags.
    git push origin --tags
    
  5. Make a release build.
    make dist
    

Publish your changes

make deploy

Changelog

Please find the changelog here: CHANGELOG.md

Authors

simple-otp was written by Kshitij Nagvekar.

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.