In a program i am writing, i use session authentication tokens that we give back to a user to have them hand in with their requests.
This is working very well but this question is about the generated token and chance of collision.
Here is the PHP code used to generate a token: bin2hex(random_bytes(32))
.
I have been considering for a while on generation of this token, should we do a quick database check that it does exist already.
I fully understand the low chances of this happening, but because it's a possibility should i check anyway? or are the chances so low that the lines of code checking are comedic from the point of view of others that read the commit?
Put another way from an info sec perspective: Is the risk assessment of one user getting into another users session a high enough danger that we should always check for session token collisions?