django-pgcryptoauth
Django hasher for PostgreSQL pgcrypto encoded passwords.
django-pgcryptoauth is a custom Django password hasher which is intended to provide authentication continuity for legacy passwords that were encrypted with the Postgres pgcrypto extension.
Since we don’t have access to the cleartext passwords, we instead just make Django understand and handle the legacy algorithm. When a user successfully logs in, Django will automatically upgrade the password to the preferred algorithm.
Source code
Dependencies
Of course, you will need to be using a PostgreSQL database with the pgcrypto extension installed.
Installation
Install the django-pgcryptoauth package:
pip install django-pgcryptoauth
Add pgcryptoauth to your INSTALLED_APPS:
INSTALLED_APPS = ( ... 'pgcryptoauth', ... )Add pgcryptoauth.hashers.PgCryptoPasswordHasher to PASSWORD_HASHERS in your Django settings:
PASSWORD_HASHERS = ( ... 'pgcryptoauth.hashers.PgCryptoPasswordHasher', )
Note: This hasher should probably at the bottom of the list so that other hashers take priority. See https://docs.djangoproject.com/en/dev/topics/auth/passwords/
Configuration
By default, pgcryptoauth will use your default database connection. However, you may instruct it to use another connection by setting PGCRYPTOAUTH_DATABASE to something else in your Django settings.:
PGCRYPTOAUTH_DATABASE = 'another_database'
Of course, this other connection must be a valid Postgres database with the pgcrypto extension and listed in your DATABASES setting:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'my_database',
'USER': 'my_user',
'PASSWORD': 'my_pass',
'HOST': '127.0.0.1',
'PORT': '',
},
'another_database': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'another_database',
'USER': 'another_user',
'PASSWORD': 'another_pass',
'HOST': '127.0.0.1',
'PORT': '',
}
}
This may be necessary if the pgcrypto extension is not (or can’t be) installed on your primary database. Especially if your primary database is not PostgreSQL!
Running test cases
Execute the unit test:
python manage.py test pgcryptoauth
Loading legacy data
Note: Legacy pgcrypto hashed passwords look like $1$BFw5nhna$XeiE8c4FInYGp3oND2l9n1. When migrating these passwords, we simply need to prefix the hash with the pgcrypto$ algorithm:
user.password = 'pgcrypto$$1$BFw5nhna$XeiE8c4FInYGp3oND2l9n1' user.save()
If you review that users password via the Django auth.user admin, you should see:
algorithm: pgcrypto hash: $1$BFw******************************************
History
v0.3 - Adds Python 3 support, supports Django 1.8+.
Metadata
Release files for django-pgcryptoauth 0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django-pgcryptoauth-0.3.tar.gz | 5.5 kB | Without provenance | Details |
Release files / django-pgcryptoauth-0.3.tar.gz
| Download URL | django-pgcryptoauth-0.3.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5ac7b1a5f098b58c5e87e53dad55111ef9384e5e8c2f2562a311e6f3ef5036ec
|
|
BLAKE2b-256 checksum How to use checksums |
3b8f65948a3648d57f6d02255d433e1a599be0291050f0e257a084969531ed57
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-pgcryptoauth 0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.