Skip to content

Instantly share code, notes, and snippets.

@MarceauKa
Created October 20, 2020 10:55
Show Gist options
  • Save MarceauKa/0c54d7199d7d317c4902c43227739bf1 to your computer and use it in GitHub Desktop.
Save MarceauKa/0c54d7199d7d317c4902c43227739bf1 to your computer and use it in GitHub Desktop.
PHP Hash - Generate hash from command line
#!/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