In PHP, the uniqid() function calculates its result based on the current time. This helps to ensure that the values โโare unique because they are not twice or twice, however this does not work on multiple servers, since it is purely time-based. Using something temporary is bad, because the number of different values โโthat uniqid() can create is very limited. Assuming PHP has been used for 25 years, it calculates up to 7.89e + 14 microseconds that have passed, and therefore the same number of values โโwould be produced for uniqid() .
This is a very large number, however, assuming that we can get a truly random salt, the chance of collision is actually much less than when using uniqid() . Possible symbols that can be used as salt:
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
This means that we use 64 different characters for a salt of 22 characters, which computes approximately 5.44e + 39 different combinations.
Thus, basically, trying to make something unique, it is actually less unique than if you were using a random source.
source share