0006-move-all-password-related-functions-in-authentic2.pa.patch
src/authentic2/passwords.py | ||
---|---|---|
2 | 2 |
import random |
3 | 3 |
import re |
4 | 4 |
import abc |
5 |
import six |
|
5 | 6 | |
6 | 7 |
from django.utils.translation import ugettext as _ |
7 | 8 |
from django.utils.module_loading import import_string |
9 |
from django.utils.functional import lazy |
|
10 |
from django.core.exceptions import ValidationError |
|
11 | ||
8 | 12 |
from . import app_settings |
9 | 13 | |
10 | 14 | |
... | ... | |
101 | 105 | |
102 | 106 |
def get_password_checker(*args, **kwargs): |
103 | 107 |
return import_string(app_settings.A2_PASSWORD_POLICY_CLASS)(*args, **kwargs) |
108 | ||
109 | ||
110 |
def validate_password(password): |
|
111 |
error = password_help_text(password, only_errors=True) |
|
112 |
if error: |
|
113 |
raise ValidationError(error) |
|
114 | ||
115 | ||
116 |
def password_help_text(password='', only_errors=False): |
|
117 |
password_checker = get_password_checker() |
|
118 |
criteria = [check.label for check in password_checker(password) if not (only_errors and check.result)] |
|
119 |
if criteria: |
|
120 |
return _('In order to create a secure password, please use at least: %s') % (', '.join(criteria)) |
|
121 |
else: |
|
122 |
return '' |
|
123 | ||
124 |
password_help_text = lazy(password_help_text, six.text_type) |
src/authentic2/validators.py | ||
---|---|---|
1 | 1 |
from __future__ import unicode_literals |
2 |
import string |
|
3 |
import re |
|
4 |
import six |
|
5 | 2 | |
6 | 3 |
import smtplib |
7 | 4 | |
8 |
from django.utils.translation import ugettext_lazy as _, ugettext
|
|
5 |
from django.utils.translation import ugettext_lazy as _ |
|
9 | 6 |
from django.utils.encoding import force_text |
10 | 7 |
from django.core.exceptions import ValidationError |
11 | 8 |
from django.core.validators import RegexValidator |
12 |
from django.utils.functional import lazy |
|
13 | 9 | |
14 | 10 |
import socket |
15 | 11 |
import dns.resolver |
16 | 12 |
import dns.exception |
17 | 13 | |
18 |
from . import app_settings, passwords |
|
14 |
from . import app_settings |
|
15 |
# keep those symbols here for retrocompatibility |
|
16 |
from .passwords import password_help_text, validate_password |
|
17 | ||
19 | 18 | |
20 | 19 |
# copied from http://www.djangotips.com/real-email-validation |
21 | 20 |
class EmailValidator(object): |
... | ... | |
39 | 38 |
pass |
40 | 39 |
return [] |
41 | 40 | |
42 | ||
43 | 41 |
def __call__(self, value): |
44 | 42 |
try: |
45 | 43 |
hostname = value.split('@')[-1] |
... | ... | |
85 | 83 |
def __init__(self, *args, **kwargs): |
86 | 84 |
self.regex = app_settings.A2_REGISTRATION_FORM_USERNAME_REGEX |
87 | 85 |
super(UsernameValidator, self).__init__(*args, **kwargs) |
88 | ||
89 | ||
90 |
def validate_password(password): |
|
91 |
error = password_help_text(password, only_errors=True) |
|
92 |
if error: |
|
93 |
raise ValidationError(error) |
|
94 | ||
95 | ||
96 |
def password_help_text(password='', only_errors=False): |
|
97 |
password_checker = passwords.get_password_checker() |
|
98 |
criteria = [check.label for check in password_checker(password) if not (only_errors and check.result)] |
|
99 |
if criteria: |
|
100 |
return ugettext('In order to create a secure password, please use at least: %s') % (', '.join(criteria)) |
|
101 |
else: |
|
102 |
return '' |
|
103 | ||
104 |
password_help_text = lazy(password_help_text, six.text_type) |
|
105 |
- |