Opened 15 years ago

Closed 15 years ago

Last modified 15 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: no UI/UX: no

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@…> 15 years ago.

Download all attachments as: .zip

Change History (3)

by Richard Davies <richard.davies@…>, 15 years ago

comment:1 by Russell Keith-Magee, 15 years ago

Resolution: duplicate
Status: newclosed

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

comment:2 by Richard Davies <richard.davies@…>, 15 years ago

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
Note: See TracTickets for help on using tickets.
Back to Top