mirror of
https://github.com/serghey-rodin/vesta.git
synced 2025-08-14 10:37:39 -07:00
sha-512 passwords func
This commit is contained in:
parent
1a7612cc66
commit
8a3f8592cc
4 changed files with 44 additions and 22 deletions
36
bin/v-generate-password-hash
Executable file
36
bin/v-generate-password-hash
Executable 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";
|
Loading…
Add table
Add a link
Reference in a new issue