Code

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#9541 closed (duplicate)

Allow wider choice of usernames

Reported by: Richard Davies <richard.davies@…> Owned by: nobody
Component: contrib.auth Version:
Severity: Keywords:
Cc: richard.davies@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

django.contrib.auth restricts usernames to 30 characters or fewer, matching \w

Whilst it's good to disallow extreme values, this constraint can be significantly relaxed to allow longer usernames and some more characters (e.g. - . / \ )

My specific need is to allow UUIDs as usernames, so I attach a patch with extends to 36 characters and allows hyphens. I would encourage the maintainers to generalize this further before check in, to an even longer length and wider range of characters.

Attachments (1)

9541-r9368-wider-choice-of-username.diff (3.4 KB) - added by Richard Davies <richard.davies@…> 5 years ago.

Download all attachments as: .zip

Change History (3)

Changed 5 years ago by Richard Davies <richard.davies@…>

comment:1 Changed 5 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #8432, #7591, and #8878 (and probably others).

comment:2 Changed 5 years ago by Richard Davies <richard.davies@…>

As a note for anyone else with a similar problem: Instead of patching Django itself, you can alternatively monkey patch against a standard Django install. In my case, the equivalent monkey patch is as below, and I include this in my application's models.py

User._meta.get_field('username').max_length = 36
from django.contrib.auth.forms import UserCreationForm, UserChangeForm, AuthenticationForm
UserCreationForm.declared_fields['username'].max_length = 36
UserCreationForm.declared_fields['username'].regex = re.compile(r'^[\w-]+$')
UserChangeForm.declared_fields['username'].max_length = 36
UserChangeForm.declared_fields['username'].regex = re.compile(r'^[\w-]+$')
AuthenticationForm.base_fields['username'].max_length = 36
#AuthenticationForm.base_fields['username'].max_length = re.compile(r'^[\w-]+$')  -- if #11127 adopted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.