creating user id's (best route)

mysql, php

Solution

There isn't really a best route for something like this. Essentially you need to ask yourself what your system requires. You may be able to use an email address as the ID, an auto-incremented number, MD5 hash, or even a heavy-entropy GUID.

Keep in mind that email addresses may change, auto-incremented numbers can be leveraged in automated exploits, and there's technically some chance of hashes colliding.

If you decided to go the route of generating a high-entropy GUID using PHP, you could do so using a function like `uniqid`.

echo uniqid(); // 513ac40699d85
echo uniqid("_", true); // _513ac3e00bfe46.78760239

The second line shows the two arguments you can provide; a prefix, and a request for more entropy, which will result in a more unique result.

Problem

I am looking for the best way to write out a php/mysql query to create unique user id's rather than using the autoincrement method in mysql. Ex: Facebook gives users a long string of numbers as a user id when singing up before you can assign a username. This string of numbers can be used to view your profile OR you can use username. I want users to be able to change username in the future, so don't want to design my system based on username. I don't know how big the site will get, so please take that into consideration with the solution. I don't want something that is going to be server intensive if there are alot of users signing up.

Original source