in reply to Re: Generate a session ID
in thread Generate a session ID

I checked it out on the system I was running it on...I have 48 randbits, and it produces 99,000 keys in 1 million attempts.

That being said, does anyone know of a good way to generate something like a session ID that's unique? I can't install modules.

Replies are listed 'Best First'.
Re^3: Generate a session ID
by Happy-the-monk (Canon) on Dec 04, 2005 at 19:41 UTC

    I can't install modules.

    Do what you can to change that parameter.

    It will help you more than a little right now, and we just can't estimate how much it will help in the future.

    Cheers, Sören

Re^3: Generate a session ID
by Your Mother (Archbishop) on Dec 04, 2005 at 21:46 UTC

    This won't be speedy but you could use fewer rands by adapting your original approach.

    print new_session_id(), $/; sub new_session_id { my $id = ''; for ( 1 .. 32 ) { $id .= sprintf "%x", rand(16); } return $id; }

    You should also see if you've got Digest/Digest::MD5 available on your system. You can do something like:

    use Digest::MD5 "md5_hex"; my @user_info = map { $ENV{$_} } grep { /USER|REMOTE/ } keys %ENV; print md5_hex( rand() . join('', @user_info) );

    Don't forget to do a search for unique ID too, there are many points of departure: Google on the pen for "unique id." Also, try vanilla "unique."

      Well, I'm using this method, right now:

      • When user A signs up, a new row is added to the MySQL table with their info.
      • They have a unique ID number assigned to them(3,4,etc) that auto-increments.
      • I then encrypt their ID number, using a cryptsalt of x. This becomes their unique session ID.