Skip to content

Instantly share code, notes, and snippets.

@potfur
Created September 17, 2015 08:59
Show Gist options
  • Save potfur/08932a22eb028df3a98f to your computer and use it in GitHub Desktop.
Save potfur/08932a22eb028df3a98f to your computer and use it in GitHub Desktop.
bcrypt cost calculator
<?php
$mooreLawConst = 18;
$defaults = 6; // from initial implementation for normal user
$monthsFromPublication = (new \DateTime('1999-12-31'))->diff(new \DateTime());
$monthsFromPublication = $monthsFromPublication->y * 12 + $monthsFromPublication->m + round($monthsFromPublication->d / 31);
$cost = $defaults + $monthsFromPublication / $mooreLawConst;
var_dump($cost);
$start = microtime(true);
password_hash('somepasswordstring', \CRYPT_BLOWFISH, ['cost' => $cost]);
var_dump(microtime(true) - $start);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment