Created
February 24, 2022 19:46
-
-
Save ozh/65a75392b7cb254131cc55afd28de99b to your computer and use it in GitHub Desktop.
Blowfish hash cost : time estimates
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
<?php | |
// Some simple benchmark functions | |
function starttime() { | |
$r = explode( ' ', microtime() ); | |
$r = $r[1] + $r[0]; | |
return $r; | |
} | |
function endtime($starttime) { | |
$r = explode( ' ', microtime() ); | |
$r = $r[1] + $r[0]; | |
$r = round($r - $starttime,4); | |
return $r.' seconds'."\n"; | |
} | |
// Let's hash with different costs and see the order of computational effort it makes | |
$password = "This is my p4ssw0rd !"; | |
$start = starttime(); | |
var_dump(password_hash($password, PASSWORD_BCRYPT, ['cost' => 4])); | |
echo endtime($start); // 0.0013 seconds | |
$start = starttime(); | |
var_dump(password_hash($password, PASSWORD_BCRYPT)); // with default 10 | |
echo endtime($start); // 0.0777 seconds | |
$start = starttime(); | |
var_dump(password_hash($password, PASSWORD_BCRYPT, ['cost' => 11])); | |
echo endtime($start); // 0.1486 seconds | |
$start = starttime(); | |
var_dump(password_hash($password, PASSWORD_BCRYPT, ['cost' => 15])); | |
echo endtime($start); // 2.3974 seconds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment