Skip to content

Instantly share code, notes, and snippets.

@Garbee
Created April 11, 2014 18:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Garbee/10491841 to your computer and use it in GitHub Desktop.
Save Garbee/10491841 to your computer and use it in GitHub Desktop.
Test PHP password_hash timing
<?php
$timeTarget = 0.2;
$cost = 9;
do {
$cost++;
$start = microtime(true);
password_hash("test", PASSWORD_BCRYPT, ["cost" => $cost]);
$end = microtime(true);
} while (($end - $start) < $timeTarget);
echo "Appropriate Cost Found: " . $cost . "\n";
Run this by setting the target time you want for a password to be hashed. Then run it to find out what a good cost level is for your hardware.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment