PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
GeXus
Forum Regular
Posts: 631 Joined: Sat Mar 11, 2006 8:59 am
Post
by GeXus » Fri Jun 20, 2008 9:32 pm
I'm using this code to create a unique hash
But I'm having instances where there are some of the same... Is that possible?
Kieran Huggins
DevNet Master
Posts: 3635 Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:
Post
by Kieran Huggins » Fri Jun 20, 2008 9:54 pm
this is a common fallacy when trying to create a random number.
chaining hashes and/or random functions actually dramatically decreases the randomness. You should only ever use one approach.
What are you trying to accomplish, exactly?
Ambush Commander
DevNet Master
Posts: 3698 Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US
Post
by Ambush Commander » Sat Jun 21, 2008 12:21 am
While it's possible, it is highly unlikely that you generated collisions. uniqid(rand(), true) should be fairly unique, as you've chained two "random" functions together. The md5 afterwards, however, decreases randomness.
Zoxive
Forum Regular
Posts: 974 Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan
Post
by Zoxive » Sat Jun 21, 2008 1:08 am
Just do a simple check to see if that md5 exists (Where ever you are putting it), it it does have it run the function again.`
Kieran Huggins
DevNet Master
Posts: 3635 Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:
Post
by Kieran Huggins » Sat Jun 21, 2008 3:04 am
better yet, take an md5 of the ( username or a rand() salt) and the current timestamp. You'll never collide.