Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#28415 closed Cleanup/optimization (fixed)

Clarify what characters ASCIIUsernameValidator and UnicodeUsernameValidator accept

Reported by: Dan Collins Owned by: nobody
Component: Documentation Version: 1.11
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Hello,

While investigating the current and historical validation rules for usernames in Django, I noticed the following inconsistency, which is visible on the following page:

https://docs.djangoproject.com/en/1.11/ref/contrib/auth/#django.contrib.auth.models.User.username_validator

username¶
Required. 150 characters or fewer. Usernames may contain alphanumeric, _, @, +, . and - characters.

but

class validators.ASCIIUsernameValidator¶
New in Django 1.10.
A field validator allowing only ASCII letters, in addition to @, ., +, -, and _. The default validator for User.username on Python 2.

class validators.UnicodeUsernameValidator¶
New in Django 1.10.
A field validator allowing Unicode letters, in addition to @, ., +, -, and _. The default validator for User.username on Python 3.

The documentation is inconsistent on whether ASCII numbers are allowed in usernames at all, and whether Unicode numbers are allowed in usernames when using the Unicode validator or Python 3.

Further, in light of this, the following paragraph isn't clear:

Usernames and Unicode

Django originally accepted only ASCII letters in usernames. Although it wasn’t a deliberate choice, Unicode characters have always been accepted when using Python 3. Django 1.10 officially added Unicode support in usernames, keeping the ASCII-only behavior on Python 2, with the option to customize the behavior using User.username_validator.

I believe that Django originally accepted only ASCII letters and numbers in usernames.

Note that there is such a thing as a Unicode number: I suspect the Unicode validator accepts all letter and number classes - not just 0-9, but also characters like ६ (Devanagari 6), ೬ (Kannada 6), ¹ (superscript), but reading the documentation makes me doubt this.

Change History (3)

comment:1 Changed 6 years ago by Tim Graham

Has patch: set
Summary: Documentation for ASCIIUsernameValidator is not consistentClarify what characters ASCIIUsernameValidator and UnicodeUsernameValidator accept
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

According to the Python docs, \w matches "Unicode word characters; this includes most characters that can be part of a word in any language, as well as numbers and the underscore." For my PR, I used the term "Unicode characters." Let me know if you think that's not sufficiently precise.

comment:2 Changed 6 years ago by GitHub <noreply@…>

Resolution: fixed
Status: newclosed

In 14172cf4:

Fixed #28415 -- Clarified what characters ASCII/UnicodeUsernameValidator accept.

comment:3 Changed 6 years ago by Tim Graham <timograham@…>

In 020c1c4:

[1.11.x] Fixed #28415 -- Clarified what characters ASCII/UnicodeUsernameValidator accept.

Backport of 14172cf4426de6c867028f1c194011c0a26e662d from master

Note: See TracTickets for help on using tickets.
Back to Top