Skip to content

Instantly share code, notes, and snippets.

@tonybolzan
Created October 23, 2012 04:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonybolzan/3936606 to your computer and use it in GitHub Desktop.
Save tonybolzan/3936606 to your computer and use it in GitHub Desktop.
Teste de tempo de hash de senhas em php
<?php
$n_pass = 200000;
$n_iter = 2;
function generate() {
return uniqid(rand(), TRUE);
}
$total_time_ini = microtime(true);
$list = array();
$i=$n_pass;
while($i--){
$list[generate()] = generate();
}
$result = array();
foreach (hash_algos() as $algo) {
$time_ini = microtime(true);
foreach ($list as $salt => $pass) {
$i=$n_iter;
while($i--){
hash($algo, $salt . $pass);
}
}
$time_end = microtime(true);
$result[$algo] = ($time_end - $time_ini);
echo $algo .' = '. $result[$algo] . PHP_EOL;
}
for($strong=4;$strong<=31;$strong++) {
$algo = 'bcrypt-'.$strong;
$time_ini = microtime(true);
foreach ($list as $salt => $pass) {
$i=$n_iter;
while($i--){
/* Método = 2a = bcrypt/blowfish
* Custo = 4 a 31
*/
crypt($pass, '$2a$' . $strong . '$' . $salt . '$');
}
}
$time_end = microtime(true);
$result[$algo] = ($time_end - $time_ini);
echo $algo .' = '. $result[$algo] . PHP_EOL;
}
echo PHP_EOL;
asort($result);
print_r($result);
echo PHP_EOL;
echo 'Total time: '.(microtime(true) - $total_time_ini);
echo PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment