You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hestiacp/bin/v-generate-password-hash

50 lines
1.1 KiB

#!/usr/local/hestia/php/bin/php
<?php
//# info: generate password hash
//# options: HASH_METHOD SALT PASSWORD
//# labels: panel
//#
//# example: v-generate-password-hash sha-512 rAnDom_string yourPassWord
//#
//# This function generates password hash
// Checking arguments
if ((empty($argv[1])) || (empty($argv[2]))) {
echo "Error: not enought arguments\n";
echo "Usage: " . $argv[0] ." HASH_METHOD SALT PASSWORD\n";
exit(1);
}
$crypt = $argv[1];
$salt = $argv[2];
if (empty($argv[3])) {
$password = file_get_contents("php://stdin");
$password = str_replace("\n",'',$password);
} else {
$password = $argv[3];
}
// Generating MD5 hash
if ($crypt == 'md5' ) {
$hash = crypt($password, '$1$'.$salt.'$');
}
// Generating SHA-512 hash
if ($crypt == 'sha-512' ) {
$hash = crypt($password, '$6$rounds=5000$'.$salt.'$');
$hash = str_replace('$rounds=5000','',$hash);
}
// Generating base64 hash
if ($crypt == 'htpasswd' ) {
$hash = crypt($password, base64_encode($password));
}
// Generating DES hash
if ($crypt == 'des' ) {
$hash = crypt($password, $salt);
}
// Printing result
echo $hash . "\n";