views:

127

answers:

3

Hi all,

I am going to use email as a username across the website, however I still need to pre-fill the mandatory username field in User model somehow.

Initially I was thinking of using a md5 hash of the email as username, but given the limitation of 30 characters it is not possible. Also I don't think I can use GUIDs for that as they are also longer than 30 chars when converted to string hex.

Any suggestions greatly appreciated!

A: 

Why would you limit the length of an email address to 30 characters? You're excluding lots of valid email addresses then.

Why can you not just use the email address as the username right away?

Alex Brasetvik
django's limitation on username field is 30 characters, which means if one was to use this field that restriction applies.
Art
Weird. That seems somewhat arbitrary.
Alex Brasetvik
Just to make sure things are clear: the 30 character limit is on the 'username' field, not the 'email' field and yes it's arbitrary but so is any other length for username. The problem here is Art is trying to auto-generate the username field (which can't be NULL) because his users log in using email address instead of username.
Van Gale
+2  A: 

I wouldn't stress too much about GUIDs being longer than 30 characters. A reasonable approach is probably to hash the GUID using something like MD5, and then trim off the last 2 characters. Your chances of a collision are effectively nil. (1630 is an awfully large number).

Dominic Rodger
+1  A: 

These links string length of a GUID, and Characters in a GUID show that a guid is really only 16 characters long. Its the ASCII equivalent that is longer. So, as long as you convert back and forth before display (or if you aren't going to display them at all), a GUID fits in the username field nicely.

Mark0978