Version 5.5 of PHP will have built-in support for BCrypt, the functions password_hash()
and password_verify()
. For PHP version 5.3.7 and later, there exists a compatibility pack, and there you can find a good implementation of how to create a salt using the function mcrypt_create_iv()
, see lines 86 and 121.
Because of this compatibility pack, you should also consider to use this functions directly, instead of writing your own, here you can find an example. Especially the creation of the salt for BCrypt is a tricky thing, and one can make a lot of mistakes.
P.S. A salt should be as random as possible (read from the random source of the operating system), because that's the best way to make it unique and unpredictable on a deterministic computer.