File: pwgen.php

package info (click to toggle)
simplesamlphp 1.16.3-1%2Bdeb10u2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 21,036 kB
  • sloc: php: 73,175; ansic: 875; sh: 83; perl: 82; xml: 52; makefile: 46
file content (47 lines) | stat: -rwxr-xr-x 1,084 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env php
<?php
/*
 * Interactive script to generate password hashes.
 *
 */


// This is the base directory of the SimpleSAMLphp installation
$baseDir = dirname(dirname(__FILE__));

// Add library autoloader
require_once($baseDir.'/lib/_autoload.php');


echo "Enter password: ";
$password = trim(fgets(STDIN));

if (empty($password)) {
    echo "Need at least one character for a password\n";
    exit(1);
}

$table = '';
foreach (array_chunk(hash_algos(), 6) as $chunk) {
    foreach ($chunk as $algo) {
        $table .= sprintf('%-13s', $algo);
    }
    $table .= "\n";
}

echo "The following hashing algorithms are available:\n".$table."\n";
echo "Which one do you want? [sha256] ";
$algo = trim(fgets(STDIN));
if (empty($algo)) {
    $algo = 'sha256';
}

if (!in_array(strtolower($algo), hash_algos(), true)) {
    echo "Hashing algorithm '$algo' is not supported\n";
    exit(1);
}

echo "Do you want to use a salt? (yes/no) [yes] ";
$s = (trim(fgets(STDIN)) == 'no') ? '' : 'S';

echo "\n  ".SimpleSAML\Utils\Crypto::pwHash($password, strtoupper($s.$algo))."\n\n";