Last active
August 29, 2015 14:08
-
-
Save phillipsharring/c0dd025b31d40e0d145b to your computer and use it in GitHub Desktop.
Code samples for this blog entry: http://www.phillipharrington.com/bcrypt-passwords-with-php-5-5/
This file contains hidden or 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
Bcrypt Passwords with PHP 5.5 |
This file contains hidden or 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
password_hash($password, $algorithm, $options = []); |
This file contains hidden or 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
$password = 'H@X04!'; | |
$hash = password_hash($password, PASSWORD_BCRYPT, ['cost' => $cost]); |
This file contains hidden or 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
// 100 milliseconds | |
// change this to your target time | |
$timeTarget = 0.1; | |
$cost = 8; | |
do { | |
$cost++; | |
$start = microtime(true); | |
password_hash('test', PASSWORD_BCRYPT, ['cost' => $cost]); | |
$end = microtime(true); | |
} while (($end - $start) < $timeTarget); | |
echo 'Appropriate Cost Found: ' . $cost . PHP_EOL; |
This file contains hidden or 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
// true, hooray! | |
password_verify($password, $hash); | |
// false | |
password_verify('not the password', $hash); | |
// false | |
password_verify($password, 'not the hash'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment