Creating a random salt

I’m trying to find a good way to create a random salt to encrypt a password as in

crypt($pw, $salt);

I’ve googled and googled but can’t find a suitable answer. One suggestion was

base64_encode($pw);

which is hardly random.
I’m using PHP 5.3
Any ideas welcome. Thanks.

What are you wanting to do?

It is better to know what your needs are and then someone can best advise you.

Why not do…


$password = "hello123";
$random_salt = md5(rand(1,1000000000000) . date("y-m-d h:i:s") . "8239fjefjwfkk");
$password = crypt($password, $random_salt);

What I want to do is create an encrypted password for use with .htaccess/.htpasswd

Ah- thanks Patche!