A reusable Django app that will invalidate all active sessions after change password.
Since Django 1.7 this feature implemented out of the box.
Installation
Install a package.
$ pip install django-password-session
Add “password_session” to your INSTALLED_APPS setting:
INSTALLED_APPS = (
...
'password_session',
)
Add middleware:
MIDDLEWARE_CLASSES = (
...
'password_session.middleware.CheckPasswordHash',
),
Make sure that you have the following settings:
INSTALLED_APPS = (
...
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
)
AUTHENTICATION_BACKENDS = (
...
'django.contrib.auth.backends.ModelBackend',
)
MIDDLEWARE_CLASSES = (
...
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
)
To avoid logging out a user from a current session you should update the session by calling the following function directly after change a password:
from password_session import update_session_auth_hash
update_session_auth_hash(request, user)
Example view
It’s a very simple view for change password just for demonstrating how to update a current session.
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
from password_session import update_session_auth_hash
def change_password_view(request):
user = request.user
user.set_password(request.POST.get('password'))
user.save()
update_session_auth_hash(request, user)
return HttpResponse("Hello, %s! Your password has been changed!" % user.username)
Requirements
Python 2.6+ or 3+
Django>=1.3,<1.7
Metadata
Release files for django-password-session 0.3.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-password-session-0.3.3.tar.gz | 4.0 kB | Without provenance | Details |
Release files / django-password-session-0.3.3.tar.gz
| Download URL | django-password-session-0.3.3.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9203604e1b82d7774eb28bef22ab42c81f227c452128c506e0a83757f9aa530e
|
|
BLAKE2b-256 checksum How to use checksums |
77e021c6c40d784726fd19c39493f9867e5738ffa0ed4a5aad6b8362602ad1e2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-password-session 0.3.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.