sha-512 passwords func

This commit is contained in:
Serghey Rodin 2015-04-04 16:49:10 +03:00
commit 8a3f8592cc
4 changed files with 44 additions and 22 deletions

36
bin/v-generate-password-hash Executable file
View file

@ -0,0 +1,36 @@
#!/usr/local/vesta/php/bin/php
<?php
//# info: generate password hash
//# options: HASH-METHOD SALT PASSWORD
//
//# The 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);
}
// Printing result
echo $hash . "\n";