Forums

This topic is locked

Need help deciding on the best way to do username checking

Posted 29 Nov 2011 17:03:44
1
has voted
29 Nov 2011 17:03:44 O V posted:
Hello everyone,

I am working on a project where the users pick a nickname while registering, by picking two words from a list. (e.g. they pick "apple" and "bar" then their nickname becomes "applebar". There is also a randomize button that picks random words from each list to form a nickname. Two users can't have the same name.

The client now wants me to change the randomize button to always generate a valid (e.g. not taken) name.

I can see several ways to do this. But I can't decide which one to use. Of course, there are many factors that would need to be taken into account to figure out which method is statistically the better one. But I just want a general opinion here really. I have several ideas but need to figure out which ones are bad and which ones are worth a shot. :-)

Method 1: When user clicks randomize, the program picks 25 random nicknames and queries the database to see if any of them exist. (e.g. select username from users where username='user1' or username='user2' or .....) If they all exist, it sends another 50 nicknames, another 100 nicknames, and so until it finds a valid nickname.

Now this method is probably the most efficient one I can think of on average, but it relies on luck and could potentially be very inefficient.

Method 2: When registration begins, the program reads a full list of usernames from the database (select username from users). From then on the decisions can all be done clientside. This method has the added bonus of being able to hide invalid options; say when you pick the first word, it has the ability to only show you the valid options for the second word.

This method is much more reliable, but it gets very inefficient as the number of users increase. There could be several potential optimizations here:

First, let me start by noting that the client is written in actionscript2, calling a php file to access the database.

- Each time the query is run, the php file can store the list of names in a text file, along with a timestamp. So every time it's called, the php file would read the list from the file first, and only query the database for new entries since the timestamp. Of course this assumes that reading a text file is faster than reading results of a query.

- Once the php file has the results, they can be compressed using LZW compression before being sent to the AS2 client.

- Once the AS2 client has the results, it can be sorted into a Hashtable (say, using the first 3 letters as the key?), to make it faster to process.

Method 3: Something in between; user picks first word, clicks randomize. The program queries the database for a list of usernames beginning with the first word (select username from users where username like 'APPLE%') then picks a suitable second word (and greys out the unsuitable ones).


Well this is all I've got for now... Please feel free to shoot down any and all of these ideas and share with me any alternative solutions you have. =)

Cheers.

Replies

Replied 18 Dec 2012 15:05:14
18 Dec 2012 15:05:14 Eric Brown replied:
no thank

Reply to this topic