Zero-Knowledge Proof Authentication System for Django
Project description
django-zk-auth
🔐 A Django authentication package using zero-knowledge proofs (ZKPs) for enhanced privacy and security.
Features
- Authenticate users via Zero-Knowledge proofs instead of passwords
- Secure and privacy-preserving login flows
- Custom authentication backends compatible with Django's auth system
- Support for passwordless user registration using cryptographic commitments
- Enhanced admin backend with additional security checks
- Easy integration and configuration with existing Django projects
Installation
pip install django-zk-auth
Configuration of Authentication Backends
To integrate Zero-Knowledge proof-based authentication into your Django project, configure the custom authentication backends provided by django-zk-auth.
Using ZKUser and Authentication Backends in Your Django Project
To integrate django-zk-auth seamlessly, you can configure your Django settings to use the provided ZKUser model and authentication backends directly.
Here is an example configuration snippet, inspired by the tests/test_settings.py file included with the package, which you can adapt for your project:
# settings.py (or your test settings)
INSTALLED_APPS = [
"django.contrib.contenttypes",
"django.contrib.auth",
"django.contrib.sessions",
"django_zk_auth", # Enables ZK authentication app
]
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": ":memory:", # In-memory DB for testing or quick dev setup
}
}
AUTH_USER_MODEL = "django_zk_auth.ZKUser" # Use the ZKUser model from the package
AUTHENTICATION_BACKENDS = [
"django_zk_auth.auth_backend.ZKAdminAuthenticationBackend", # Admin login with ZK proof
"django_zk_auth.auth_backend.ZKAuthenticationBackend", # Standard ZK user login
"django_zk_auth.auth_backend.ZKPasswordlessBackend", # Passwordless/registration backend
"django.contrib.auth.backends.ModelBackend", # Django's fallback backend (optional)
]
# Optional: Speed up tests by simplifying password hashing
PASSWORD_HASHERS = [
"django.contrib.auth.hashers.MD5PasswordHasher",
]
# Additional recommended settings
USE_TZ = True
TIME_ZONE = "UTC"
This setup allows your project to authenticate users through Zero-Knowledge proofs instead of conventional password authentication, enabling secure and privacy-preserving login flows and Leverage Django’s built-in authentication fallback if needed.
Explanation of Authentication Backends:
Authentication Backends Overview
-
ZKAuthenticationBackend
Implements authentication using Zero-Knowledge proofs submitted by users. It verifies proof validity, account status, and manages failed login attempts, fully integrating with Django's user model through the customZKUser. -
ZKPasswordlessBackend
A fallback backend designed primarily for user registration flows. It authenticates users based on cryptographic commitments and registration proofs without requiring passwords. -
ZKAdminAuthenticationBackend (Optional)
ExtendsZKAuthenticationBackendwith additional security layers for Django admin access, ensuring only active staff users with valid ZK proofs can log in.
This modular backend design preserves the zero-knowledge property, enhancing security and privacy beyond traditional password schemes.
Usage in Your Django Application
-
User Login Flow:
Replace traditional password authentication forms with a mechanism that collects Zero-Knowledge proof data (zk_proof) and a challengenonce. These values are then passed to Django’sauthenticate()method, which invokes the custom backends. -
Django Authentication Integration:
Your views, middleware, or REST framework authentication classes can call:from django.contrib.auth import authenticate, login user = authenticate(request, username=username, zk_proof=zk_proof_data, nonce=nonce) if user is not None: login(request, user) # User is now authenticated via Zero-Knowledge proof else: # Handle authentication failure
Running Tests
The package includes an example tests/test_settings.py which configures an in-memory database and minimal apps for testing the authentication backend in isolation.
pytest -s tests/test_zksystem.py
Running Specific Tests by Class
pytest -k TestZKSystem -s tests/test_zk_system.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_zk_auth-1.0.1.tar.gz.
File metadata
- Download URL: django_zk_auth-1.0.1.tar.gz
- Upload date:
- Size: 49.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
584e2adf164bce3ec93d2091ae9a49ad2af97279e1d97894533c3b08b21c0653
|
|
| MD5 |
81f0faecd7263ac46868a66f9c886a08
|
|
| BLAKE2b-256 |
46389c91ce94994342b1fb427927dd0933e95f57993190e20dd7a534e99b3ad5
|
File details
Details for the file django_zk_auth-1.0.1-py3-none-any.whl.
File metadata
- Download URL: django_zk_auth-1.0.1-py3-none-any.whl
- Upload date:
- Size: 55.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de6b036b330defb767d2fa30bb281577987cde75939c867b5ecedfe6ffde8a13
|
|
| MD5 |
866fdd755f9a17eb14bf446eda20bf3c
|
|
| BLAKE2b-256 |
a2b004cd80fdbcab0f6ac1c8d7d97fbe9dc640291af0cd8e4725465e354bcb16
|