From 2a09404792f9d369718143fdfbe9530fe2e60912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anssi=20K=C3=A4=C3=A4ri=C3=A4inen?= Date: Mon, 30 Apr 2012 21:35:04 +0300 Subject: [PATCH] Reset password hashers cache on settings_changed. --- django/contrib/auth/hashers.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/django/contrib/auth/hashers.py b/django/contrib/auth/hashers.py index 58246852a8..52d204cce6 100644 --- a/django/contrib/auth/hashers.py +++ b/django/contrib/auth/hashers.py @@ -1,6 +1,8 @@ import hashlib +from django.dispatch import receiver from django.conf import settings +from django.test.signals import setting_changed from django.utils import importlib from django.utils.datastructures import SortedDict from django.utils.encoding import smart_str @@ -14,6 +16,13 @@ UNUSABLE_PASSWORD = '!' # This will never be a valid encoded hash HASHERS = None # lazily loaded from PASSWORD_HASHERS PREFERRED_HASHER = None # defaults to first item in PASSWORD_HASHERS +@receiver(setting_changed) +def reset_hashers(**kwargs): + if kwargs['setting'] == 'PASSWORD_HASHERS': + global HASHERS, PREFERRED_HASHER + HASHERS = None + PREFERRED_HASHER = None + def is_password_usable(encoded): return (encoded is not None and encoded != UNUSABLE_PASSWORD)