Last active
December 15, 2015 11:42
-
-
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()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
//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