Ticket #5786: django-auth-username-relax-character-restrictions.diff

File django-auth-username-relax-character-restrictions.diff, 4.2 KB (added by clayg, 15 years ago)

diff from the top-level trunk directory including tests

  • django/contrib/auth/forms.py

    diff -uNr --exclude=.svn django-trunk/django/contrib/auth/forms.py django-5786/django/contrib/auth/forms.py
    old new  
    1111    """
    1212    A form that creates a user, with no privileges, from the given username and password.
    1313    """
    14     username = forms.RegexField(label=_("Username"), max_length=30, regex=r'^\w+$',
    15         help_text = _("Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores)."),
    16         error_message = _("This value must contain only letters, numbers and underscores."))
     14    username = forms.RegexField(label=_("Username"), max_length=30, regex=r'^[\w.@+-]+$',
     15        help_text = _("Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only."),
     16        error_message = _("This value may contain only letters, numbers and @/./+/-/_ characters."))
    1717    password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
    1818    password2 = forms.CharField(label=_("Password confirmation"), widget=forms.PasswordInput,
    1919        help_text = _("Enter the same password as above, for verification."))
     
    4545        return user
    4646
    4747class UserChangeForm(forms.ModelForm):
    48     username = forms.RegexField(label=_("Username"), max_length=30, regex=r'^\w+$',
    49         help_text = _("Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores)."),
    50         error_message = _("This value must contain only letters, numbers and underscores."))
     48    username = forms.RegexField(label=_("Username"), max_length=30, regex=r'^[\w.@+-]+$',
     49        help_text = _("Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only."),
     50        error_message = _("This value may contain only letters, numbers and @/./+/-/_ characters."))
    5151   
    5252    class Meta:
    5353        model = User
  • django/contrib/auth/models.py

    diff -uNr --exclude=.svn django-trunk/django/contrib/auth/models.py django-5786/django/contrib/auth/models.py
    old new  
    177177
    178178    Username and password are required. Other fields are optional.
    179179    """
    180     username = models.CharField(_('username'), max_length=30, unique=True, help_text=_("Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores)."))
     180    username = models.CharField(_('username'), max_length=30, unique=True, help_text=_("Required. 30 characters or fewer. Letters, numbers and @/./+/-/_ characters"))
    181181    first_name = models.CharField(_('first name'), max_length=30, blank=True)
    182182    last_name = models.CharField(_('last name'), max_length=30, blank=True)
    183183    email = models.EmailField(_('e-mail address'), blank=True)
  • django/contrib/auth/tests/forms.py

    diff -uNr --exclude=.svn django-trunk/django/contrib/auth/tests/forms.py django-5786/django/contrib/auth/tests/forms.py
    old new  
    2121# The username contains invalid data.
    2222
    2323>>> data = {
    24 ...     'username': 'jsmith@example.com',
     24...     'username': 'jsmith!',
    2525...     'password1': 'test123',
    2626...     'password2': 'test123',
    2727... }
     
    2929>>> form.is_valid()
    3030False
    3131>>> form["username"].errors
    32 [u'This value must contain only letters, numbers and underscores.']
     32[u'This value may contain only letters, numbers and @/./+/-/_ characters.']
    3333
    3434# The verification password is incorrect.
    3535
     
    6565# The success case.
    6666
    6767>>> data = {
    68 ...     'username': 'jsmith2',
     68...     'username': 'jsmith2@example.com',
    6969...     'password1': 'test123',
    7070...     'password2': 'test123',
    7171... }
     
    7373>>> form.is_valid()
    7474True
    7575>>> form.save()
    76 <User: jsmith2>
     76<User: jsmith2@example.com>
    7777
    7878# The user submits an invalid username.
    7979
     
    189189>>> form.is_valid()
    190190False
    191191>>> form['username'].errors
    192 [u'This value must contain only letters, numbers and underscores.']
     192[u'This value may contain only letters, numbers and @/./+/-/_ characters.']
    193193
    194194
    195195### PasswordResetForm
Back to Top