Skip to main content

A reusable Django app that implements Zero-Knowledge Proof (Schnorr protocol) authentication — no passwords ever leave the client.

Project description

django-zkp-auth

A reusable Django authentication app implementing the Schnorr Interactive Zero-Knowledge Proof protocol.

The user's passphrase never leaves their browser. Only a derived public key is stored on the server.


How It Works

Registration and login follow the Schnorr protocol:

Step Party Action
1 Client Derives private key x = SHA256(password) % (P-1), computes public key y = G^x mod P. Sends only y to server.
2 Client Picks random nonce r, computes commitment t = G^r mod P. Sends (username, t).
3 Server Generates random challenge c. Stores (user_id, t, c) in session. Returns c.
4 Client Computes proof response s = (r + c*x) % (P-1). Sends s.
5 Server Verifies G^s ≡ t * y^c (mod P). Logs user in on success.

Security rests on the discrete logarithm problem — knowing s, t, c, and y does not reveal x.


Installation

pip install django-zkp-auth

Quick Start

1. Add to INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    'django_zkp_auth',
]

2. Include the URLs in your project's urls.py:

from django.urls import path, include

urlpatterns = [
    path('auth/', include('django_zkp_auth.urls', namespace='django_zkp_auth')),
    ...
]

3. Run migrations:

python manage.py migrate

4. Visit /auth/register/ to create an account and /auth/login/ to authenticate.


Configuration

All settings are optional. Add them to your settings.py to override defaults:

Setting Default Description
ZKP_PRIME_P 2695139 Prime modulus P. Use a 2048-bit prime for production.
ZKP_GENERATOR_G 2 Generator G of the multiplicative group mod P.
ZKP_LOGOUT_REDIRECT_URL '/' URL to redirect to after logout.

Example:

# settings.py
ZKP_PRIME_P = 2695139          # demo value — replace for production
ZKP_GENERATOR_G = 2
ZKP_LOGOUT_REDIRECT_URL = '/home/'

Production note: The default prime is intentionally small for readability and thesis demonstration. For a production deployment, replace it with a 2048-bit safe prime from RFC 3526 or NIST recommendations.


Template Customisation

The package ships with a standalone dark-themed base template. To override any template, place your version in your project's template directory under the same namespaced path:

<your_project>/
└── templates/
    └── django_zkp_auth/
        ├── base.html      # override the layout/nav
        ├── login.html     # override the login page
        └── register.html  # override the registration page

Make sure this directory is listed in TEMPLATES[0]['DIRS'] in your settings.py.

The base template exposes the following blocks:

Block Purpose
title <title> tag content
brand Brand name in the navbar
extra_head Additional <head> content (CSS, meta tags)
content Main page body
extra_scripts Scripts loaded before </body>

Programmatic Usage

ZKPVerifier and ZKPProver are importable for tests and server-side simulations:

from django_zkp_auth.zkp_utils import ZKPVerifier, ZKPProver

# Server: generate a challenge
challenge = ZKPVerifier.generate_challenge()

# Server: verify a proof
is_valid = ZKPVerifier.verify_proof(
    public_key_y=public_key,
    commitment_t=commitment,
    challenge_c=challenge,
    response_s=response,
)

# Client simulation (e.g. in tests)
private_key = ZKPProver.generate_private_key(password_hash_int)
public_key  = ZKPProver.generate_public_key(private_key)

License

MIT

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_zkp_auth-0.1.0.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

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

django_zkp_auth-0.1.0-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file django_zkp_auth-0.1.0.tar.gz.

File metadata

  • Download URL: django_zkp_auth-0.1.0.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for django_zkp_auth-0.1.0.tar.gz
Algorithm Hash digest
SHA256 99289cd20d66c661c4dfb0c25c255653bc8eef444d823b4f6ec38fb11a2c847d
MD5 e28416cbc492c6d3350281216511bd2e
BLAKE2b-256 01245c298b3489b5ee48405c7be9e57a0787e00eaced0807fa63a138e12fa06d

See more details on using hashes here.

File details

Details for the file django_zkp_auth-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_zkp_auth-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ceb5ef63c131d92483fce744a54c4f9c0692fefb5cdc2caff08e90425c49dddd
MD5 bc96508b4118f7fc81b5d5b6d1178174
BLAKE2b-256 6bfb0dc55e76253bdc5c2ff9882a310fb6072b360539523645f52efe9e75eb6a

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