same name count in auth_backends.py leads to issues in some cases #47

Closed
iiilx opened this Issue Jul 6, 2011 · 0 comments

2 participants

@iiilx

I was tracking down a bug for more than a few hours and it came down to this. Basically I had a registered username of ben86lee2 in my app, and when I tried to register another account where the screen_name was ben86lee, the following code said there was already 1 user whose username started with "ben86lee". So it then tried to register ben86lee as ben86lee2 because of the "+1" step in the code below. But there already is a ben86lee2, so it finally gave an integrity error. So basically maybe the code could be changed to not use __startswith and just do exact matches instead. Or any other solution that would avoid this issue. Basically this error would occur anytime a username of "abc2" is registered but "abc" is not. Of course switch out "abc" with any username and the same error would occur.

same_name_count = (User.objects
                               .filter(username__startswith=screen_name)
                               .count())
if name_count:
            username = '%s%d' % (nickname, name_count + 1)

suggesting something like:

same_name_count = (User.objects
                               .filter(username=screen_name)
                               .count())
 if name_count:
            username = '%s%d' % (nickname, name_count + 1)

Thanks for your time and effort on this great open source package.

@shabda shabda closed this Sep 25, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment