Update: I'm seeing a lot of people making the assumption that these are for Web Sessions, or similarly short-life-span situations. I should have been more clear. I'm using these for a database application that is exported to a proprietary application -- so Apache anything is useless for this. Also, some of these sessions involve loading several hundred GB of data and can stay open for days, so lowering collisions over a span of time is important.
Please scan through the replies for specific details.
The following alternate was suggested by simonm. I haven't personally tested it, but it seems like a Better Way.use strict; use Digest::MD5; use Sys::Hostname; sub md5sid { my $hostname = hostname(); my $serial = new Digest::MD5; $serial->add($hostname); # Having the time in hex form is useful $serial->add(sprintf "%X", time()); # This is sort of slow, but strong. Reducing # the param for rand() will speed things, but # make collisions more likely. for (my $i=1; $i < rand(2345678); $i++ ) { $serial->add(chr(int(rand(223))+32)); } my $session = $serial->hexdigest(); return $session; }#-sub md5sid
See the Data::UUID module on CPAN.use Data::UUID; use constant IDGenerator => Data::UUID->new(); sub new_sid { IDGenerator->create() }
In reply to MD5-based Unique Session ID Generator by radiantmatrix
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |