ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
13require_once($baseDir.'/lib/_autoload.php');
14
15
16echo "Enter password: ";
17$password = trim(fgets(STDIN));
18
19if (empty($password)) {
20 echo "Need at least one character for a password\n";
21 exit(1);
22}
23
24$table = '';
25foreach (array_chunk(hash_algos(), 6) as $chunk) {
26 foreach ($chunk as $algo) {
27 $table .= sprintf('%-13s', $algo);
28 }
29 $table .= "\n";
30}
31
32echo "The following hashing algorithms are available:\n".$table."\n";
33echo "Which one do you want? [sha256] ";
34$algo = trim(fgets(STDIN));
35if (empty($algo)) {
36 $algo = 'sha256';
37}
38
39if (!in_array(strtolower($algo), hash_algos(), true)) {
40 echo "Hashing algorithm '$algo' is not supported\n";
41 exit(1);
42}
43
44echo "Do you want to use a salt? (yes/no) [yes] ";
45$s = (trim(fgets(STDIN)) == 'no') ? '' : 'S';
46
47echo "\n ".SimpleSAML\Utils\Crypto::pwHash($password, strtoupper($s.$algo))."\n\n";
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
$algo
Definition: pwgen.php:34
$s
Definition: pwgen.php:45
$password
Definition: pwgen.php:17
if(empty($password)) $table
Definition: pwgen.php:24
$baseDir
Definition: pwgen.php:10