Wednesday, October 26, 2011

Re: Long usernames in auth_user?

This is a known limitation and it's something that people _want_ to get fixed (but just merely increasing the length isn't helpful, because soon someone comes along with the new length + 1 and the same problem occurs). The issue is that the django.contrib.auth User model while providing a minimum (sort of) set of fields for a user, doesn't let you enhance it's internals very well. I think the core dev's are mostly waiting for someone to come up with a good solution to this problem.

Now to answer your other question. 

There are 2 general ways of handling this, and neither one is perfect. One is to do as you did and modify the db to allow longer usernames, also being careful to modify anyplace that validates that the length is 30 so that it works across the sites.

The other method is to create your own auth handler (Pinax comes with one) that let's you authenticate against the email field on auth.User. Then in your signup process you save their email address to this field, and generate the username (I'm fond of UUID's for this). The final (optional) piece of this puzzle is to monkey patch User.__unicode__ to return self.email instead of self.username.

On Wednesday, October 26, 2011 at 4:38 PM, Joakim Hove wrote:

Hello,

I have been using a (in general quite popular I think ...) convention
where the e-mail address has been used as username. I have solved this
by asking the user for an e-mail address and a password, and then used
the supplied e-mail address both as username and e-mail address when
instantiating a User object. This has worked fine up until now.

Now suddenly someone came along with an e-mail address which was
longer than the 30 characters limit imposed on the username; and
things went to pieces. I have Googled this topic but did not find any
clear cut simple solution, altough I am definitely not the first one
to stumble over this problem.

So two questions:

1) I modified the (development) database directly increasing the field
size from 30 to 75; and that seemed to work nicely; but I am not very
comfortable about the solution. What do you say?

2) Any chance of changing this in a future release?

Joakim

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment