File: pwgen.php

package info (click to toggle)
simplesamlphp 1.14.11-1%2Bdeb9u2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 15,024 kB
  • sloc: php: 72,337; xml: 1,078; python: 376; sh: 220; perl: 185; makefile: 57
file content (47 lines) | stat: -rwxr-xr-x 1,058 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())) {
	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";