ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
pwgen.php
Go to the documentation of this file.
1 #!/usr/bin/env php
2 <?php
3 /*
4  * Interactive script to generate password hashes.
5  *
6  */
7 
8 
9 // This is the base directory of the SimpleSAMLphp installation
10 $baseDir = dirname(dirname(__FILE__));
11 
12 // Add library autoloader
13 require_once($baseDir.'/lib/_autoload.php');
14 
15 
16 echo "Enter password: ";
17 $password = trim(fgets(STDIN));
18 
19 if (empty($password)) {
20  echo "Need at least one character for a password\n";
21  exit(1);
22 }
23 
24 $table = '';
25 foreach (array_chunk(hash_algos(), 6) as $chunk) {
26  foreach ($chunk as $algo) {
27  $table .= sprintf('%-13s', $algo);
28  }
29  $table .= "\n";
30 }
31 
32 echo "The following hashing algorithms are available:\n".$table."\n";
33 echo "Which one do you want? [sha256] ";
34 $algo = trim(fgets(STDIN));
35 if (empty($algo)) {
36  $algo = 'sha256';
37 }
38 
39 if (!in_array(strtolower($algo), hash_algos(), true)) {
40  echo "Hashing algorithm '$algo' is not supported\n";
41  exit(1);
42 }
43 
44 echo "Do you want to use a salt? (yes/no) [yes] ";
45 $s = (trim(fgets(STDIN)) == 'no') ? '' : 'S';
46 
47 echo "\n ".SimpleSAML\Utils\Crypto::pwHash($password, strtoupper($s.$algo))."\n\n";
$s
Definition: pwgen.php:45
$algo
Definition: pwgen.php:34
$password
Definition: pwgen.php:17
exit
Definition: backend.php:16
if(empty($password)) $table
Definition: pwgen.php:24
$baseDir
Definition: pwgen.php:10