tarak / django-password-policies

Django unicode-aware password policies.
Other
59 stars 92 forks source link

KeyError '_password_policies_change_required' #31

Closed xusy2k closed 9 years ago

xusy2k commented 9 years ago

If I set PASSWORD_USE_HISTORY to False I always get this exception

tarak commented 9 years ago

Can you provide the whole stack trace?

xusy2k commented 9 years ago

Environment:

Request Method: GET Request URL: http://localhost:8000/admin/

Django Version: 1.5.12 Python Version: 2.7.6 Installed Applications: ('django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.admin', 'django.contrib.admindocs', 'password_policies') Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'password_policies.middleware.PasswordChangeMiddleware')

Traceback: File "/home/xus/.virtualenvs/test_django/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response

  1. response = middleware_method(request) File "/home/xus/.virtualenvs/test_django/local/lib/python2.7/site-packages/password_policies/middleware.py" in process_request
  2. return self._redirect(request) File "/home/xus/.virtualenvs/test_django/local/lib/python2.7/site-packages/password_policies/middleware.py" in _redirect
  3. if request.session[self.required]: File "/home/xus/.virtualenvs/test_django/local/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in getitem
  4. return self._session[key]

Exception Type: KeyError at /admin/ Exception Value: '_password_policies_change_required'

tarak commented 9 years ago

Thx! Can you try to remove the 'password_policies.middleware.PasswordChangeMiddleware'. Won't work anyway if you set PASSWORD_USE_HISTORY to false I think...

The middleware is not very reliable and needs to be rewritten.

Is there a reason why you need the middleware and disable the usage of the password history at the same time?

xusy2k commented 9 years ago

Thx! It worked! Only reason for need the middleware and disable the usage of the password history is for testing PASSWORD_CHECK_ONLY_AT_LOGIN = False feature, but I don't want to use historic passwords. Finally I set PASSWORD_HISTORY_COUNT = 1

tarak commented 9 years ago

So this issue could be closed?

xusy2k commented 9 years ago

Yes!, It worked for me

tarak commented 9 years ago

Closing as it seems to work for @xusy2k.