Created
October 20, 2020 10:55
-
-
Save MarceauKa/0c54d7199d7d317c4902c43227739bf1 to your computer and use it in GitHub Desktop.
PHP Hash - Generate hash from command line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
array_shift($argv); | |
$password = $argv[0]; | |
$algo = $argv[1] ?? 'md5'; | |
if (empty($argv)) { | |
die(vsprinf("Usage: %s\n%s\n%s", [ | |
'phphash', | |
'{string}: The string to hash', | |
'{algo}: Hash algo to use, defaults to md5 (see: hash_algos())', | |
])); | |
} | |
if (false === in_array($algo, hash_algos())) { | |
die(vsprintf('Invalid algo %s, available algos are: %s', [ | |
$algo, | |
implode(', ', hash_algos()), | |
])); | |
} | |
echo hash($algo, $password); | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment