Skip to content

Commit

Permalink
Updated username validation rules
Browse files Browse the repository at this point in the history
  • Loading branch information
felixoi committed Dec 29, 2018
1 parent 225578d commit 539e04f
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions spongeauth/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,22 @@ def validate_username(username):
errs.append(ValidationError(
_('Username must be at least 3 characters long.'),
code='username_min_length'))
if re.search(r'[^\w.-]', username):
if re.search(r'[^\w_-]', username):
errs.append(ValidationError(
_('Username must only include numbers, letters, and underscores.'),
_('Username must only include numbers, letters, underscores and dashes.'),
code='username_charset'))
if re.search(r'\W', username[0]):
if re.search(r'[^\w_]', username[0]):
errs.append(ValidationError(
_('Username must begin with a number, letter or underscore.'),
_('Username must begin with a letter, number or underscore.'),
code='username_initial_charset'))
if re.search(r'[^A-Za-z0-9]', username[-1]):
if re.search(r'[^\w_]', username[-1]):
errs.append(ValidationError(
_('Username must end with a letter or number.'),
_('Username must end with a letter, number or underscore.'),
code='username_ending_charset'))
if re.search(r'[-_.]{2,}', username):
if re.search(r'[-_]{2,}', username):
errs.append(ValidationError(
_('Username must not contain two special characters in a row.'),
code='username_double_special'))
if re.search(
r'\.(js|json|css|htm|html|xml|jpg|jpeg|png|gif|bmp|ico|tif|tiff|woff)$',
username):
errs.append(ValidationError(
_('Username must not end with a confusing file suffix.'),
code='username_file_suffix'))
if errs:
raise ValidationError(errs)

Expand Down

0 comments on commit 539e04f

Please sign in to comment.