Skip to content

Instantly share code, notes, and snippets.

@phpdave
Last active December 15, 2015 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save phpdave/885d7aa34fb0f35eca3f to your computer and use it in GitHub Desktop.
Save phpdave/885d7aa34fb0f35eca3f to your computer and use it in GitHub Desktop.
Testing PHP7 Alpha 's new features. Using the new random_bytes() for password_hash()
//Easy User-land CSPRNG - cryptographically strong random bytes and int generators
echo '#### Easy User-land CSPRNG ####'. PHP_EOL;
$randomStr = random_bytes($length = 160);
$randomInt = random_int($min = 0, $max = 127);
var_dump($randomStr,$randomInt);
<?
//Using random_bytes as the salt for a password hash. random_bytes is a CSPRNG (cryptographically strong random number (bytes) generator)
echo '#### Password Hash ####'. PHP_EOL;
$options = [
'cost' => 11,
'salt' => random_bytes($length = 22),
];
echo password_hash("rasmuslerdorf", PASSWORD_BCRYPT, $options)."\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment