Reset password hashers cache on settings_changed.

This commit is contained in:
Anssi Kääriäinen 2012-04-30 21:35:04 +03:00
parent ddfc7c2530
commit 2a09404792
1 changed files with 9 additions and 0 deletions

View File

@ -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)