Skip to content

Commit 8f92f09

Browse files
author
Allen Short
committed
Disallow all-digit usernames (bug 862121)
1 parent 681237f commit 8f92f09

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

apps/users/forms.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ class UsernameMixin:
158158

159159
def clean_username(self):
160160
name = self.cleaned_data['username']
161+
# All-digits usernames are disallowed since they can be
162+
# confused for user IDs in URLs. (See bug 862121.)
163+
if name.isdigit():
164+
raise forms.ValidationError(_('Usernames cannot contain only digits.'))
161165
slug_validator(name, lower=False,
162166
message=_('Enter a valid username consisting of letters, numbers, '
163167
'underscores or hyphens.'))

apps/users/tests/test_forms.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,15 @@ def test_blacklisted_username(self):
437437
self.assertFormError(r, 'form', 'username',
438438
'This username cannot be used.')
439439

440+
def test_alldigit_username(self):
441+
data = {'email': 'testo@example.com',
442+
'password': 'xxxlonger',
443+
'password2': 'xxxlonger',
444+
'username': '8675309', }
445+
r = self.client.post('/en-US/firefox/users/register', data)
446+
self.assertFormError(r, 'form', 'username',
447+
'Usernames cannot contain only digits.')
448+
440449
def test_blacklisted_password(self):
441450
BlacklistedPassword.objects.create(password='password')
442451
data = {'email': 'testo@example.com',

0 commit comments

Comments
 (0)