Skip to content

Commit dbc4ea2

Browse files
authored
apply same max password length between forms and zxcvbn (#17630)
* apply same max password length between forms and zxcvbn [email protected] implements a max_length parameter with a default of 72. Move our MAX_PASSWORD_SIZE to a constant and use it for the password forms as well as zxcvbn validator * translations
1 parent 8922f50 commit dbc4ea2

File tree

4 files changed

+31
-28
lines changed

4 files changed

+31
-28
lines changed

warehouse/accounts/forms.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,14 @@
4040
from warehouse.accounts.models import DisableReason, ProhibitedEmailDomain
4141
from warehouse.accounts.services import RECOVERY_CODE_BYTES
4242
from warehouse.captcha import recaptcha
43+
from warehouse.constants import MAX_PASSWORD_SIZE
4344
from warehouse.email import (
4445
send_password_compromised_email_hibp,
4546
send_recovery_code_used_email,
4647
)
4748
from warehouse.events.tags import EventTag
4849
from warehouse.i18n import localize as _
4950

50-
# Taken from passlib
51-
MAX_PASSWORD_SIZE = 4096
52-
5351
# Common messages, set as constants to keep them from drifting.
5452
INVALID_EMAIL_MESSAGE = _("The email address isn't valid. Try again.")
5553
INVALID_PASSWORD_MESSAGE = _("The password is invalid. Try again.")

warehouse/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@
1414
ONE_GIB = 1 * 1024 * 1024 * 1024
1515
MAX_FILESIZE = 100 * ONE_MIB
1616
MAX_PROJECT_SIZE = 10 * ONE_GIB
17+
# Taken from passlib
18+
MAX_PASSWORD_SIZE = 4096

warehouse/forms.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from wtforms.validators import InputRequired, ValidationError
2020
from zxcvbn import zxcvbn
2121

22+
from warehouse.constants import MAX_PASSWORD_SIZE
2223
from warehouse.i18n import KNOWN_LOCALES
2324
from warehouse.utils.http import is_valid_uri
2425

@@ -68,7 +69,9 @@ def __call__(self, form, field):
6869
raise ValidationError(f"Invalid field name: {fieldname!r}")
6970

7071
# Actually ask zxcvbn to check the strength of the given field's data.
71-
results = zxcvbn(field.data, user_inputs=user_inputs)
72+
results = zxcvbn(
73+
field.data, user_inputs=user_inputs, max_length=MAX_PASSWORD_SIZE
74+
)
7275

7376
# Determine if the score is too low, and if it is produce a nice error
7477
# message, *hopefully* with suggestions to make the password stronger.

warehouse/locale/messages.pot

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,111 +14,111 @@ msgstr ""
1414
msgid "Locale updated"
1515
msgstr ""
1616

17-
#: warehouse/accounts/forms.py:54 warehouse/accounts/forms.py:292
17+
#: warehouse/accounts/forms.py:52 warehouse/accounts/forms.py:290
1818
msgid "The email address isn't valid. Try again."
1919
msgstr ""
2020

21-
#: warehouse/accounts/forms.py:55
21+
#: warehouse/accounts/forms.py:53
2222
msgid "The password is invalid. Try again."
2323
msgstr ""
2424

25-
#: warehouse/accounts/forms.py:57
25+
#: warehouse/accounts/forms.py:55
2626
msgid ""
2727
"The username is invalid. Usernames must be composed of letters, numbers, "
2828
"dots, hyphens and underscores. And must also start and finish with a "
2929
"letter or number. Choose a different username."
3030
msgstr ""
3131

32-
#: warehouse/accounts/forms.py:74
32+
#: warehouse/accounts/forms.py:72
3333
msgid "Null bytes are not allowed."
3434
msgstr ""
3535

36-
#: warehouse/accounts/forms.py:88
36+
#: warehouse/accounts/forms.py:86
3737
msgid "No user found with that username"
3838
msgstr ""
3939

40-
#: warehouse/accounts/forms.py:109
40+
#: warehouse/accounts/forms.py:107
4141
#, python-brace-format
4242
msgid "TOTP code must be ${totp_length} digits."
4343
msgstr ""
4444

45-
#: warehouse/accounts/forms.py:129
45+
#: warehouse/accounts/forms.py:127
4646
#, python-brace-format
4747
msgid "Recovery Codes must be ${recovery_code_length} characters."
4848
msgstr ""
4949

50-
#: warehouse/accounts/forms.py:143
50+
#: warehouse/accounts/forms.py:141
5151
msgid "Choose a username with 50 characters or less."
5252
msgstr ""
5353

54-
#: warehouse/accounts/forms.py:161
54+
#: warehouse/accounts/forms.py:159
5555
msgid ""
5656
"This username is already being used by another account. Choose a "
5757
"different username."
5858
msgstr ""
5959

60-
#: warehouse/accounts/forms.py:174 warehouse/accounts/forms.py:223
61-
#: warehouse/accounts/forms.py:236
60+
#: warehouse/accounts/forms.py:172 warehouse/accounts/forms.py:221
61+
#: warehouse/accounts/forms.py:234
6262
msgid "Password too long."
6363
msgstr ""
6464

65-
#: warehouse/accounts/forms.py:206
65+
#: warehouse/accounts/forms.py:204
6666
#, python-brace-format
6767
msgid ""
6868
"There have been too many unsuccessful login attempts. You have been "
6969
"locked out for ${time}. Please try again later."
7070
msgstr ""
7171

72-
#: warehouse/accounts/forms.py:239
72+
#: warehouse/accounts/forms.py:237
7373
msgid "Your passwords don't match. Try again."
7474
msgstr ""
7575

76-
#: warehouse/accounts/forms.py:273
76+
#: warehouse/accounts/forms.py:271
7777
msgid "The email address is too long. Try again."
7878
msgstr ""
7979

80-
#: warehouse/accounts/forms.py:345
80+
#: warehouse/accounts/forms.py:343
8181
msgid "You can't use an email address from this domain. Use a different email."
8282
msgstr ""
8383

84-
#: warehouse/accounts/forms.py:360
84+
#: warehouse/accounts/forms.py:358
8585
msgid ""
8686
"This email address is already being used by this account. Use a different"
8787
" email."
8888
msgstr ""
8989

90-
#: warehouse/accounts/forms.py:371
90+
#: warehouse/accounts/forms.py:369
9191
msgid ""
9292
"This email address is already being used by another account. Use a "
9393
"different email."
9494
msgstr ""
9595

96-
#: warehouse/accounts/forms.py:411 warehouse/manage/forms.py:140
96+
#: warehouse/accounts/forms.py:409 warehouse/manage/forms.py:140
9797
#: warehouse/manage/forms.py:742
9898
msgid "The name is too long. Choose a name with 100 characters or less."
9999
msgstr ""
100100

101-
#: warehouse/accounts/forms.py:417
101+
#: warehouse/accounts/forms.py:415
102102
msgid "URLs are not allowed in the name field."
103103
msgstr ""
104104

105-
#: warehouse/accounts/forms.py:506
105+
#: warehouse/accounts/forms.py:504
106106
msgid "Invalid TOTP code."
107107
msgstr ""
108108

109-
#: warehouse/accounts/forms.py:523
109+
#: warehouse/accounts/forms.py:521
110110
msgid "Invalid WebAuthn assertion: Bad payload"
111111
msgstr ""
112112

113-
#: warehouse/accounts/forms.py:592
113+
#: warehouse/accounts/forms.py:590
114114
msgid "Invalid recovery code."
115115
msgstr ""
116116

117-
#: warehouse/accounts/forms.py:601
117+
#: warehouse/accounts/forms.py:599
118118
msgid "Recovery code has been previously used."
119119
msgstr ""
120120

121-
#: warehouse/accounts/forms.py:631
121+
#: warehouse/accounts/forms.py:629
122122
msgid "The username isn't valid. Try again."
123123
msgstr ""
124124

0 commit comments

Comments
 (0)