note 9026 added to crypt

From: Date: Thu, 12 Oct 2000 02:51:06 +0000
Subject: note 9026 added to crypt
Groups: php.notes 
Request: Send a blank email to php-notes+get-6397@lists.php.net to get a copy of this message
I use the following function to generate my own salt, adopted from the Perl Cookbook. It generates two-character salts but you can easily change it to suit your purpose. As was mentioned in the User Notes for srand(), it's bad omen to seed repeatedly, so you might want to remove the srand() line if your script is so written that you would have already seeded at some point before calling the function. function gensalt() { srand((double)microtime()*1000000); $saltseeds = array('.','/','0','1','2','3','4','5','6','7','8','9', 'a','b','c','d','e','f','g','h','i','j','k','l','m', 'n','o','p','q','r','s','t','u','v','w','x','y','z', 'A','B','C','D','E','F','G','H','I','J','K','L','M', 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z'); return $saltseeds[rand(0,63)] . $saltseeds[rand(0,63)]; } $password = 'blahblah'; $salt = gensalt(); $crypted = crypt($password,$salt); echo "crypt('$password','$salt') is '$crypted'\n"; http://www.php.net/manual/function.crypt.php

« previous php.notes (#6397) next »