Perl: the Markov chain saw | |
PerlMonks |
Re^4: MD5-based Unique Session ID Generatorby pelagic (Priest) |
on Aug 19, 2004 at 20:56 UTC ( [id://384451]=note: print w/replies, xml ) | Need Help?? |
As we don't want to exercise Cargo Cult let's see what's done in this snippet: "$rand_id" is composed of a couple of items to generate uniqueness: "time()", "rand()" and "$$" are good for that while "{}", ref to an anonymous hash, doesnt help much, because it's always the same. It is possible to create more than 1 session id within 1 second but it's very unlikely to get more than 1 duplicate random within 1 second. So uniqueness is achieved. It's a good idea to hash the "readable" id to put it in a regular, non human readable string format. This hashing does not improve the "uniqueness" of the id. It makes it more difficult to be guessed or hacked but that's it! To hash it a second time doesn't do anything, nor good nor bad(besides performance). pelagic
In Section
Cool Uses for Perl
|
|