Re: duplicate md5 hash's
| From: | Guy Bowden | Date: | Thu, 09 Dec 2004 12:22:42 +0000 |
| Subject: | Re: duplicate md5 hash's | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-203808@lists.php.net to get a copy of this message | ||
Thanks for the tip... I have now implemented a while loop to make sure that it goes into the db, as you say this should never actually loop, but if it does it should only loop once..
kind of extra security..
cheers
Richard Davey wrote:
Hello Guy, Thursday, December 9, 2004, 11:39:27 AM, you wrote: GB> $hash = md5(uniqid($message)); GB> where message is a string that the user will input. GB> How likely is it that this hash might be repeated? GB> I'm using the hash as a primary key in a database - the user gets sent GB> the hash as part of a url to retrieve the details of that database row. GB> (its a basic send to a friend e-card system). GB> Is there any way that the same hash could have been generated more than GB> once? It's extremely unlikely (I cannot give you any stats as to how unlikely though, sorry). However why not just stick the $hash creation into a self-checking loop. I.e. make the hash - check the database - does it exist already? - If not then the hash is good, else repeat the process. Using uniqid will give you a unique hash on each occasion so this process shouldn't take very long at all even if it did find a duplicate a few times (unlikely!) Best regards, Richard Davey