Skip to main content

A reusable Django app that will invalidate all active sessions after change password.

Project description

A reusable Django app that will invalidate all active sessions after change password.

Since Django 1.7 this feature implemented out of the box.

https://badge.fury.io/py/django-password-session.png https://api.travis-ci.org/atugushev/django-password-session.png https://coveralls.io/repos/atugushev/django-password-session/badge.png?branch=master

Installation

  1. Install a package.

$ pip install django-password-session
  1. Add “password_session” to your INSTALLED_APPS setting:

INSTALLED_APPS = (
    ...
    'password_session',
)
  1. Add middleware:

MIDDLEWARE_CLASSES = (
    ...
    'password_session.middleware.CheckPasswordHash',
),
  1. 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',
)
  1. 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+

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-password-session-0.3.1.tar.gz (3.9 kB view details)

Uploaded Source

File details

Details for the file django-password-session-0.3.1.tar.gz.

File metadata

File hashes

Hashes for django-password-session-0.3.1.tar.gz
Algorithm Hash digest
SHA256 657af0428da07128547712574352c03cf446a756037bf2911131d64840cfb47a
MD5 bccde30fe549161e896eecf721e22d98
BLAKE2b-256 82faafa44e4e491bb3285d7bd0f6555e8ce3b7656f11a0d81a0119c204ed9ddb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page