Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unicode characters in Django usernames

I am developing a website using Django 1.4 and I use django-registration for the signup process. It turns out that Unicode characters are not allowed as usernames, whenever a user enters e.g. a Chinese character as part of username the registration fails with:

This value may contain only letters, numbers and @/./+/-/_ characters.

Is it possible to change it so Unicode characters are allowed in usernames? If yes, how can I do it? Also, can it cause any problem?

like image 973
piokuc Avatar asked Aug 29 '12 19:08

piokuc


2 Answers

It is really not a problem - because this character restriction is in UserCreationForm (or RegistrationForm in django-registration) only as I remember, and you can easily make your own since field in database is just normal TextField.

But those restriction is there not without a reason. One of the possible problems I can think of now is creating links - usernames are often used for that and it may cause a problem. There is also bigger possibility of fake accounts with usernames looking the same but being in fact different characters, etc.

like image 124
jasisz Avatar answered Nov 18 '22 07:11

jasisz


Django 1.10 now officially supports unicode usernames, see:

The User model in django.contrib.auth originally only accepted ASCII letters in usernames. Although it wasn’t a deliberate choice, Unicode characters have always been accepted when using Python 3.

The username validator now explicitly accepts Unicode letters by default on Python 3 only. This default behavior can be overridden by changing the username_validator attribute of the User model, or to any proxy of that model, using either ASCIIUsernameValidator or UnicodeUsernameValidator. Custom user models may also use those validators.

like image 21
Cesar Canassa Avatar answered Nov 18 '22 08:11

Cesar Canassa