Generate a unique username for django.contrib.auth

2011-01-12 Thread Micah Carrick
I've got my site's authentication working with and email and password only--no username (thanks to Shawn Milochik for helping me with that). However, I still need to put in a username to make the User model happy. I was hoping to have "user" as a prefix and then some unique number. I cannot simply

Re: Generate a unique username for django.contrib.auth

2011-01-12 Thread marco carminati
Hi Micah On Jan 12, 10:11 pm, Micah Carrick wrote: > I've got my site's authentication working with and email and password > only--no username (thanks to Shawn Milochik for helping me with that). > However, I still need to put in a username to make the User model happy. I > was hoping to have "us

Re: Generate a unique username for django.contrib.auth

2011-01-12 Thread Eric Chamberlain
We use a base64 or base36 (if you want compatibility with the contrib.admin) encoded UUID, or generate a random 30-character string, the odds of a collision is quite low. On Jan 12, 2011, at 1:11 PM, Micah Carrick wrote: > I've got my site's authentication working with and email and password >

Re: Generate a unique username for django.contrib.auth

2011-01-12 Thread Acorn
Why not just use incremental numeric user IDs? On 12 January 2011 21:23, Eric Chamberlain wrote: > We use a base64 or base36 (if you want compatibility with the contrib.admin) > encoded UUID, or generate a random 30-character string, the odds of a > collision is quite low. > > On Jan 12, 2011,

Re: Generate a unique username for django.contrib.auth

2011-01-12 Thread Micah Carrick
Thanks folks. Here's what I have now. Not the most elegant but it's the best I can come up with so far. First, I'm generating a random string for the username so that the form will validate. After the record is saved I change the username to "user_" and the user ID. This way it looks a little less

Re: Generate a unique username for django.contrib.auth

2011-01-12 Thread Eric Chamberlain
Because the id is not known until after the record is saved, so you'd have to generate some non-colliding filler value anyway. Using incremental numbers can also leak usage information to the users. On Jan 12, 2011, at 1:52 PM, Acorn wrote: > Why not just use incremental numeric user IDs? >

Re: Generate a unique username for django.contrib.auth

2011-01-14 Thread Ian Clelland
On Wed, Jan 12, 2011 at 1:11 PM, Micah Carrick wrote: > I cannot use uuid4().hex because that's 32 characters... I need <30. uuid4().hex[:30] is almost as random as uuid4().hex There are no timers, MAC addresses, or other non-random sections in a UUID4, so taking any 30-character slice from it s

Re: Generate a unique username for django.contrib.auth

2011-01-15 Thread Martin J. Laubach
> I cannot simply copy the email to the username because the username must be > less than 30 characters and, after looking into my database, many email > addresses go over that. Note that you can fix that quite easily by putting something like this for f in User._meta.fields: if f.n