What are the chances of md5 outputting same values. I cant think of anything, but want to get other opinions.
function theid(){
$rand = random_int("1000000","9999999");
$idcont = date("d.m.Y").$rand.time("h:i:s").$rand;
$sysid = md5($idcont);
return $sysid;
}
$oneid = theid();
it does not hash pass I'm using it to generate unique ids for my system. Checking each id is not a good option as id will be stored in different places.
CONCLUSION. Thanks all. By comments in this post i had to sit back and rethink how id are carried true system. I will cut back on using auto_increment for user id, use uniqid() to handle system events and use something like hash_password() for other part i did not even touch here. Better pull my sleeves up ...
I don't see the point using md5 for generating unique ids. Obviously you are not trying to create cryptographically secure value and it would not be secure in your example anyway. Use uniqid() function instead. It's designed for non-collision. It creates a unique identifier based on the current time in microseconds. You can use the second argument (more entropy) to create more unique values.
$uid = uniqid('some prefix', true);
md5 is not secure anymore. Theoretically it's possible to have same hash from different origin, it's not easy but it's possible. It seems you want to generate unique ids so maybe standard uuid it's an option to you: https://docs.mongodb.com/manual/geospatial-queries/
Thanks all. By comments in this post i had to sit back and rethink how id are carried true system. I will cut back on using auto_increment for user id, use uniqid() to handle system events and use something like hash_password() for other part i did not even touch here. Better pull my sleeves up ...