hashing passwords in PHP code example
Example 1: hash a password php
password_hash("MySuperSafePassword!", PASSWORD_DEFAULT)
password_verify("MySuperSafePassword!", $hashed_password)
Example 2: php hash password
<?php
$options = [
'cost' => 12,
];
echo password_hash("rasmuslerdorf", PASSWORD_BCRYPT, $options);
?>
Example 3: php hash password
$time = 0.1;
$cost = 10;
do
{
$cost++;
$start = microtime(true);
password_hash('test', PASSWORD_BCRYPT, ['cost' => $cost]);
$end = microtime(true);
}
while (($end - $start) < $time);
echo 'Cost found: ' . $cost;
Example 4: php hash password
$password = 'my secret password';
$options = ['cost' => 12];
$hash = password_hash($password, PASSWORD_DEFAULT, $options);