Re: [PHP] duplicate md5 hash's

2004-12-09 Thread Richard Lynch
>> 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).

As I understand it (or don't, rather) the odds are one in 2,147,...,... (2
billion)

But that's only in theory.

In practice, I think people have demonstrated that it's not really 1 in 2
billion.

It's still damned unlikely, but making *SURE* with the loop you've got is
cheap and easy, so I'd stick with that.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] duplicate md5 hash's

2004-12-09 Thread Guy Bowden
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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] duplicate md5 hash's

2004-12-09 Thread Guy Bowden
Hi,
I know this is highly unlikely... but I have this code:
$hash = md5(uniqid($message));
where message is a string that the user will input.
How likely is it that this hash might be repeated?
I'm using the hash as a primary key in a database - the user gets sent 
the hash as part of a url to retrieve the details of that database row.

(its a basic send to a friend e-card system).
Is there any way that the same hash could have been generated more than 
once?

Cheers,
Guy
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] duplicate md5 hash's

2004-12-09 Thread Richard Davey
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
-- 
 http://www.launchcode.co.uk - PHP Development Services
 "I am not young enough to know everything." - Oscar Wilde

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php