Skip to main content

OTP system based on cache

Project description

from build.lib.django_cache_otp.decorators import skip_if_existsfrom django_cache_otp import generate_otp

django-cache-otp

A simple Django package for generating and validating OTPs using Django's cache framework.

Table of Contents

Installation

Install via pip:

pip install django-cache-otp

Setup

Configure Cache (Using Redis)

set up your cache settings settings.py:

CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://127.0.0.1:6379/1",
    }
}

Usage

from django_cache_otp import generate_otp, validate_otp

otp = generate_otp("username", otp_length=6, timeout=60)  # Example: 123456, valid for 60 seconds
is_valid = validate_otp("username", otp)  # Returns True or False

if you want to not generate new OTP when username already has one:

otp = generate_otp("username", otp_length=6, timeout=60, skip_if_exists=True)
# return None if username already has an OTP

Features

  • Easy integration with Django's cache framework.
  • Customizable OTP length and timeout.
  • Supports various cache backends (e.g., Redis, Memcached).
  • Using SECRET_KEY for encrypt otp.

Contributing

Contributions are very welcome! Please follow these steps:

  • Fork the repository.
  • Create a new branch (git checkout -b feature/YourFeature).
  • Make your changes and commit them (git commit -m 'Add some feature').
  • Push to the branch (git push origin feature/YourFeature).
  • Open a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_cache_otp-0.2.0b2.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_cache_otp-0.2.0b2-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file django_cache_otp-0.2.0b2.tar.gz.

File metadata

  • Download URL: django_cache_otp-0.2.0b2.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for django_cache_otp-0.2.0b2.tar.gz
Algorithm Hash digest
SHA256 70a563eee897da990caf499c73c880d578b5a024228daaceeed94b0ee7cc4ddb
MD5 4353bd72763eb63a882ee50720d599a5
BLAKE2b-256 1a8d0d017c7ae6368ea77046b5ccd1a5cc8a46cd824cf24f7f1591ab690902ec

See more details on using hashes here.

File details

Details for the file django_cache_otp-0.2.0b2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_cache_otp-0.2.0b2-py3-none-any.whl
Algorithm Hash digest
SHA256 638e0c2b653f73a723c41bb977f2bd8748853d6da4c1d0f165dffddefa40cb50
MD5 60df9ee57621e7a0b022ee2de81f0b06
BLAKE2b-256 c424a71090ea7d80fe6939e66fcf29c9f550ecf49c183cfaa97dc6ddef08258b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page