Django field and widget for Altcha CAPTCHA.
Project description
Django Altcha
Django Altcha is a Django library that provides easy integration of Altcha CAPTCHA into your Django forms, enhancing user verification with configurable options.
By default, CAPTCHA validation operates in a fully self-hosted mode, eliminating the need for external services while ensuring privacy and control over the verification process.
Django Altcha is secure by default, featuring built-in protection against replay attacks to ensure each challenge is validated only once. This helps safeguard your forms from repeated or spoofed submissions without requiring additional configuration.
Installation
-
Install the package:
pip install django-altcha
-
Add to
INSTALLED_APPS:Update your Django project's
settings.py:INSTALLED_APPS = [ # Other installed apps "django_altcha", ]
-
Set your secret HMAC key:
This key is used to HMAC-sign ALTCHA challenges and must be kept secret. Treat it like a password: use a secure, 64-character hex string.
Update your Django project's
settings.py:ALTCHA_HMAC_KEY="your_secret_hmac_key"
[!NOTE] You can generate a new secured HMAC key using:
python -c "import secrets; print(secrets.token_hex(64))"
Usage
Adding the CAPTCHA Field to Your Form
To add the Altcha CAPTCHA field to a Django form, import AltchaField and add it to
your form definition:
from django import forms
from django_altcha import AltchaField
class MyForm(forms.Form):
captcha = AltchaField()
Configuration Options
You can pass configuration options to AltchaField that are supported by Altcha.
These options are documented at
Altcha's website integration guide.
Example with additional options:
from django import forms
from django_altcha import AltchaField
class MyForm(forms.Form):
captcha = AltchaField(
floating=True, # Enables floating behavior
debug=True, # Enables debug mode (for development)
# Additional options supported by Altcha
)
Register a URL to Provide the Challenge
By default, challenge data is generated by the AltchaField and embedded directly
into the rendered HTML using the challengejson option.
Alternatively, you can provide a URL that the Altcha widget’s JavaScript will fetch to
retrieve the challenge, using the challengeurl option.
This approach is especially useful for enabling features like refetchonexpire,
which only work when using a challengeurl (not challengejson).
A ready-to-use AltchaChallengeView is available in django_altcha.
To enable it, register the view in your urlpatterns, for example:
from django.urls import path
from django_altcha import AltchaChallengeView
urlpatterns += [
path("altcha/challenge/", AltchaChallengeView.as_view(), name="altcha_challenge"),
]
Once the URL is registered, you can configure your AltchaField to use it via the
challengeurl option:
from django.urls import reverse_lazy
from django import forms
from django_altcha import AltchaField
class MyForm(forms.Form):
captcha = AltchaField(
challengeurl=reverse_lazy("altcha_challenge"),
)
[!NOTE] You can customize the challenge generation by passing options directly when registering the view. For example:
AltchaChallengeView.as_view(max_number=2000000)
Replay Attack Protection
Django Altcha automatically protects against replay attacks by ensuring each challenge can only be used once. When a challenge is successfully validated, it is stored in a cache and any subsequent attempt to reuse the same challenge will be rejected.
This protection is enabled by default and requires no additional configuration for single-process deployments.
[!IMPORTANT] By default, replay protection uses Django's
defaultcache backend, which isLocMemCacheunless you configure it otherwise. This in-memory cache is not shared across workers. If you run multiple workers (e.g., with gunicorn or uwsgi), configure a shared cache backend such as Redis or Memcached.
Settings
ALTCHA_HMAC_KEY
Required. This key is used to HMAC-sign ALTCHA challenges and must be kept secret.
ALTCHA_CACHE_ALIAS
Django cache alias used for replay attack protection.
Defaults to "default".
If your default cache is already a shared backend (Redis, Memcached, database),
no extra configuration is needed.
If you want to use a dedicated cache for ALTCHA, define one and point to it:
Using Redis or Memcached:
CACHES = {
'altcha': {
'BACKEND': 'django.core.cache.backends.redis.RedisCache',
'LOCATION': 'redis://127.0.0.1:6379',
}
}
ALTCHA_CACHE_ALIAS = 'altcha'
Using Database Caching:
If you prefer not to set up Redis or Memcached, Django's built-in database cache is a simple alternative:
CACHES = {
'altcha': {
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
'LOCATION': 'altcha_cache',
}
}
ALTCHA_CACHE_ALIAS = 'altcha'
Then create the cache table:
python manage.py createcachetable
ALTCHA_CHALLENGE_EXPIRE
Challenge expiration duration in milliseconds. Defaults to 20 minutes as per Altcha security recommendations.
ALTCHA_JS_URL
URL of the Altcha JavaScript file. Defaults to the bundled django-altcha file.
ALTCHA_INCLUDE_TRANSLATIONS
Whether to include Altcha translations.
Defaults to False.
ALTCHA_JS_TRANSLATIONS_URL
URL of the Altcha translations JavaScript file. Defaults to the bundled django-altcha file.
Only loaded when ALTCHA_INCLUDE_TRANSLATIONS is True.
ALTCHA_VERIFICATION_ENABLED
Set to False to skip Altcha validation altogether.
Defaults to True.
Contributing
We welcome contributions to improve this library. Feel free to submit issues or pull requests!
License
This project is licensed under the MIT License. See the LICENSE file for details.
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_altcha-0.10.0.tar.gz.
File metadata
- Download URL: django_altcha-0.10.0.tar.gz
- Upload date:
- Size: 59.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd8c32405a5cb7fbb66873f04f1374321095aad8b8c0ed8c88fa373179cd5d33
|
|
| MD5 |
01870cf4b3c5f86ee8bf27a1edde0226
|
|
| BLAKE2b-256 |
686cac79a60fefd5505d972b5d071945155866e7c41cfc7ac7510ae656bafcc5
|
Provenance
The following attestation bundles were made for django_altcha-0.10.0.tar.gz:
Publisher:
pypi-release.yml on aboutcode-org/django-altcha
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_altcha-0.10.0.tar.gz -
Subject digest:
bd8c32405a5cb7fbb66873f04f1374321095aad8b8c0ed8c88fa373179cd5d33 - Sigstore transparency entry: 1070650011
- Sigstore integration time:
-
Permalink:
aboutcode-org/django-altcha@8c0fd2243ae32923b7c100a7070f960176525d06 -
Branch / Tag:
refs/tags/v0.10.0 - Owner: https://github.com/aboutcode-org
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-release.yml@8c0fd2243ae32923b7c100a7070f960176525d06 -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_altcha-0.10.0-py3-none-any.whl.
File metadata
- Download URL: django_altcha-0.10.0-py3-none-any.whl
- Upload date:
- Size: 50.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db0404b11030aa45b433dbfba310bd88b21b20412b1e14e7b389b67b1d81bfa1
|
|
| MD5 |
b97bf310858aab066e3e5258f42ab18b
|
|
| BLAKE2b-256 |
cd0cd1872b7464e0f7c76eb3b39d6785d9725133c2e7169a0b8ba696fb6d64ae
|
Provenance
The following attestation bundles were made for django_altcha-0.10.0-py3-none-any.whl:
Publisher:
pypi-release.yml on aboutcode-org/django-altcha
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_altcha-0.10.0-py3-none-any.whl -
Subject digest:
db0404b11030aa45b433dbfba310bd88b21b20412b1e14e7b389b67b1d81bfa1 - Sigstore transparency entry: 1070650013
- Sigstore integration time:
-
Permalink:
aboutcode-org/django-altcha@8c0fd2243ae32923b7c100a7070f960176525d06 -
Branch / Tag:
refs/tags/v0.10.0 - Owner: https://github.com/aboutcode-org
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-release.yml@8c0fd2243ae32923b7c100a7070f960176525d06 -
Trigger Event:
push
-
Statement type: