diff --git a/account/compat.py b/account/compat.py index 94704db1..113bcb22 100644 --- a/account/compat.py +++ b/account/compat.py @@ -5,6 +5,12 @@ except ImportError: from django.urls import resolve, reverse, NoReverseMatch # noqa +if django.VERSION >= (1, 9, 0): + from django.contrib.auth.password_validation import validate_password +else: + def validate_password(password, user=None, password_validators=None): + pass + def is_authenticated(user): if django.VERSION >= (1, 10): diff --git a/account/forms.py b/account/forms.py index efbf24a3..6edb8b20 100644 --- a/account/forms.py +++ b/account/forms.py @@ -2,6 +2,8 @@ import re +from .compat import validate_password + try: from collections import OrderedDict except ImportError: @@ -88,6 +90,10 @@ def clean(self): if "password" in self.cleaned_data and "password_confirm" in self.cleaned_data: if self.cleaned_data["password"] != self.cleaned_data["password_confirm"]: raise forms.ValidationError(_("You must type the same password each time.")) + dummy_user = get_user_model() + dummy_user.username = self.cleaned_data.get("username") + dummy_user.email = self.cleaned_data.get("email") + validate_password(self.cleaned_data["password"], dummy_user) return self.cleaned_data