Skip to content

Instantly share code, notes, and snippets.

@thiagoeliasr
Created January 16, 2017 18:37
Show Gist options
  • Save thiagoeliasr/47fec01ec7b367a88e116004a27da7fe to your computer and use it in GitHub Desktop.
Save thiagoeliasr/47fec01ec7b367a88e116004a27da7fe to your computer and use it in GitHub Desktop.
Tools class, to generate Laravel-Format Hash, including Salt and Cost.
<?php
class Tools {
public static function generateLaravelHash($cost, $salt, $pass)
{
return password_hash($pass, PASSWORD_BCRYPT, [
'cost' => $cost,
'salt' => $salt
]);
}
public static function checkLaravelHash($pass, $hash)
{
return (crypt($pass, $hash) === $hash);
}
}
//testing
echo Tools::generateLaravelHash(10, 'VQUUdxdHwwDl6LSGm1jbeNN', '123456');
if (Tools::checkLaravelHash('123456', '$2y$10$VQUUdxdHwwDl6LSGm1jbe.SeY3UirFCld2tlOM.ms1DhdeAPb/lr6')) {
echo "True";
} else {
echo "False";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment