PHP Classes

File: web/SSO/bin/pwgen.php

Recommend this page to a friend!
  Classes of william amed   Raptor 2   web/SSO/bin/pwgen.php   Download  
File: web/SSO/bin/pwgen.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Raptor 2
Framework that takes routes from annotations
Author: By
Last change:
Date: 8 years ago
Size: 1,066 bytes
 

Contents

Class file image Download
#!/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";