code.fastix.org

Dateiansicht:

Datei:Projekte -> PHP:password-hash-generator -> password-hash-generator.php
md5:88e362c37b634441f85712b9ef761f93
sha1:74265f9196f73062bc4fee840e58422c8ba769ae
Download-Link:Download
  1. <?php
  2. $translator = new i10n();
  3.  
  4. if ( ! isset( $_POST['STRING'] ) ) {
  5.         $_POST['STRING'] = '';
  6. }
  7.  
  8. $output = '';
  9.  
  10. if ( ! empty( $_POST['STRING'] ) and $_POST['STRING'] and ! empty( $_POST['trimString'] ) ) {
  11.         $_POST['STRING'] = trim( $_POST['STRING'] );
  12. }
  13.  
  14. if ( defined( 'PASSWORD_BCRYPT'  ) ) {
  15.         $arrPHPMethods[] = 'PASSWORD_BCRYPT';
  16.         $arrPHPMmethods['PASSWORD_BCRYPT'] = PASSWORD_BCRYPT;
  17. }
  18. if ( defined( 'PASSWORD_ARGON2I' ) ) {
  19.         $arrPHPMethods[] = 'PASSWORD_ARGON2I';
  20.         $arrPHPMmethods['PASSWORD_ARGON2I'] = PASSWORD_ARGON2I;
  21. }
  22. if ( defined( 'PASSWORD_ARGON2ID' ) ) {
  23.         $arrPHPMethods[] = 'PASSWORD_ARGON2ID';
  24.         $arrPHPMmethods['PASSWORD_ARGON2ID'] = PASSWORD_ARGON2ID;
  25. }
  26.  
  27. $arrPHPOpenSSLMethods = openssl_get_md_methods();
  28.  
  29. $arrUnixSSLMethods = false;
  30. if ( '' != trim( `which openssl` ) ) {
  31.         $arrUnixSSLMethods = getOpenSSLDigests();
  32. }
  33.  
  34. $arrCryptMethods = [];
  35. if ( defined( 'CRYPT_STD_DES' ) and 1 == CRYPT_STD_DES )         $arrCryptMethods[] = 'STD_DES';
  36. if ( defined( 'CRYPT_EXT_DES' ) and 1 == CRYPT_EXT_DES )         $arrCryptMethods[] = 'EXT_DES';
  37. if ( defined( 'CRYPT_MD5' ) and 1 == CRYPT_MD5 )                         $arrCryptMethods[] = 'MD5';
  38. if ( defined( 'CRYPT_BLOWFISH' ) and 1 == CRYPT_BLOWFISH ) {
  39.         $arrCryptMethods[] = 'BLOWFISH-2a';
  40.         $arrCryptMethods[] = 'BLOWFISH-2x';
  41.         $arrCryptMethods[] = 'BLOWFISH-2y';
  42. }
  43. if ( defined( 'CRYPT_SHA256' ) and 1 == CRYPT_SHA256 )   $arrCryptMethods[] = 'SHA-256';
  44. if ( defined( 'CRYPT_SHA512' ) and 1 == CRYPT_SHA512 )   $arrCryptMethods[] = 'SHA-512';
  45.  
  46. $arrOtherMethods[] = 'PHP-md5()';
  47. $arrOtherMethods[] = 'PHP-sha1()';
  48. $arrOtherMethods[] = 'Old Unix passwd';
  49. $arrOtherMethods[] = 'Old Unix passwd ($1$)';
  50. $arrOtherMethods[] = 'Old Apache <= 2.2';
  51. $arrOtherMethods[] = 'Apache > 2.2';
  52. $arrOtherMethods[] = 'Old MySQL-passwd()';
  53. filter_var( $arrPHPMethods, FILTER_SANITIZE_FULL_SPECIAL_CHARS );
  54. $selectorPHP  = '<legend for="PHPMethode">' . $translator -> get('PHP-password_hash()-methods') . ':</legend><select onchange="clearHash();" id="PHPMethode" name="PHPMethode">' . PHP_EOL . '<option value="">' . $translator -> get('None of them') . '</option>' . PHP_EOL ;
  55. foreach ( $arrPHPMethods as $sMethod ) {
  56.  
  57.         if ( isset( $_POST['PHPMethode'] ) and $_POST['PHPMethode'] == $sMethod ) {
  58.                 $selectorPHP .= '<option selected="selected" value="' . $sMethod . '">' . $sMethod . '</option>' . PHP_EOL;
  59.         } else {
  60.                 $selectorPHP .= '<option value="' . $sMethod . '">' . $sMethod . '</option>' . PHP_EOL;
  61.         }
  62. }
  63. $selectorPHP .= '</select>' . PHP_EOL;
  64.  
  65. filter_var( $arrPHPOpenSSLMethods, FILTER_SANITIZE_FULL_SPECIAL_CHARS );
  66. $selectorPHPOpenSSL  = '<legend for="PHPOpenSSLMethode">' . $translator -> get('PHP-openssl_digest() and output translating') . ':</legend><select onchange="clearHash();" id="PHPOpenSSLMethode" name="PHPOpenSSLMethode">' . PHP_EOL . '<option value="">' . $translator -> get('None of them') . '</option>' . PHP_EOL ;
  67. foreach ( $arrPHPOpenSSLMethods as $sMethod ) {
  68.         if ( isset( $_POST['PHPOpenSSLMethode'] ) and $_POST['PHPOpenSSLMethode'] == $sMethod ) {
  69.                 $selectorPHPOpenSSL .= '<option selected="selected" value="' . $sMethod . '">' . $sMethod . '</option>' . PHP_EOL;
  70.         } else {
  71.                 $selectorPHPOpenSSL .= '<option value="' . $sMethod . '">' . $sMethod . '</option>' . PHP_EOL;
  72.         }
  73. }
  74. $selectorPHPOpenSSL .= '</select>' . PHP_EOL;
  75. $outputmethod = '<select onchange="clearHash();" name="outputMethodPHPOpenSSL">
  76. <option value="hex">hexadecimal</option>
  77. ';
  78. if ( isset( $_POST['outputMethodPHPOpenSSL'] ) and $_POST['outputMethodPHPOpenSSL'] == 'base64' ) {
  79.         $PHPOpenSSLbase64 = true;
  80.         $outputmethod .= '<option selected="selected" value="base64">base64</option>';
  81. } else {
  82.         $outputmethod .= '<option value="base64">base64</option>';
  83.         $PHPOpenSSLbase64 = false;
  84. }
  85. $outputmethod .= '
  86. </select>
  87. ';
  88. $selectorPHPOpenSSL .= $outputmethod;
  89.  
  90. if ( $arrUnixSSLMethods ) {
  91.         filter_var( $arrUnixSSLMethods, FILTER_SANITIZE_FULL_SPECIAL_CHARS );
  92.         $selectorUnixOpenSSL  = '<legend for="UnixOpenSSLMethode">' . $translator -> get('Unix-OpenSSL') . ':</legend><select onchange="clearHash();" id="UnixOpenSSLMethode" name="UnixOpenSSLMethode">' . PHP_EOL . '<option value="">' . $translator -> get('None of them') . '</option>' . PHP_EOL ;
  93.         foreach ( $arrUnixSSLMethods as $sMethod ) {
  94.                 if ( isset( $_POST['UnixOpenSSLMethode'] ) and $_POST['UnixOpenSSLMethode'] == $sMethod ) {
  95.                         $selectorUnixOpenSSL .= '<option selected="selected"  value="' . $sMethod . '">' . $sMethod . '</option>' . PHP_EOL;
  96.                 } else {
  97.                         $selectorUnixOpenSSL .= '<option value="' . $sMethod . '">' . $sMethod . '</option>' . PHP_EOL;
  98.                 }
  99.         }
  100.         $selectorUnixOpenSSL .= '</select>' . PHP_EOL;
  101.         $outputmethod = '<select onchange="clearHash();" name="outputMethodUnixOpenSSL">
  102.         <option value="hex">hexadecimal</option>
  103.         ';
  104.         if ( isset( $_POST['outputMethodUnixOpenSSL'] ) and $_POST['outputMethodUnixOpenSSL'] == 'base64' ) {
  105.                 $outputmethod .= '<option selected="selected" value="base64">base64</option>';
  106.                 $UnixOpenSSLbase64 = true;
  107.         } else {
  108.                 $outputmethod .= '<option value="base64">base64</option>';
  109.                 $UnixOpenSSLbase64 = false;
  110.         }
  111.         $outputmethod .= '</select>' . PHP_EOL;
  112.         $selectorUnixOpenSSL .= $outputmethod;
  113. }
  114.  
  115. filter_var( $arrCryptMethods, FILTER_SANITIZE_FULL_SPECIAL_CHARS );
  116. $selectorCrypt  = '<legend for="CryptMethode">' . $translator -> get('PHP-crypt()-methods') . ':</legend><select onchange="clearHash();" id="CryptMethode" name="CryptMethode">' . PHP_EOL . '<option value="">' . $translator -> get('None of them') . '</option>' . PHP_EOL ;
  117. foreach ( $arrCryptMethods as $sMethod ) {
  118.         if ( isset( $_POST['CryptMethode'] ) and $_POST['CryptMethode'] == $sMethod ) {
  119.                 $selectorCrypt .= '<option selected="selected" value="' . $sMethod . '">' . $sMethod . '</option>' . PHP_EOL;
  120.         } else {
  121.                 $selectorCrypt .= '<option value="' . $sMethod . '">' . $sMethod . '</option>' . PHP_EOL;
  122.         }
  123. }
  124. $selectorCrypt .= '</select>' . PHP_EOL;
  125.  
  126. filter_var( $arrOtherMethods, FILTER_SANITIZE_FULL_SPECIAL_CHARS );
  127. $selectorOther  = '<legend for="OtherMethode">' . $translator -> get('Other Methods') . ':</legend><select onchange="clearHash();" id="OtherMethode" name="OtherMethode">' . PHP_EOL . '<option value="">' . $translator -> get('None of them') . '</option>' . PHP_EOL ;
  128. foreach ( $arrOtherMethods as $sMethod ) {
  129.  
  130.         if ( isset( $_POST['OtherMethode'] ) and $_POST['OtherMethode'] == $sMethod ) {
  131.                 $selectorOther .= '<option selected="selected" value="' . $sMethod . '">' . $sMethod . '</option>' . PHP_EOL;
  132.         } else {
  133.                 $selectorOther .= '<option value="' . $sMethod . '">' . $sMethod . '</option>' . PHP_EOL;
  134.         }
  135. }
  136. $selectorOther .= '</select>' . PHP_EOL;
  137.  
  138. if  ( ! empty ( $_POST['PHPMethode'] ) ) {
  139.         if ( isset( $_POST['STRING'] ) and $_POST['STRING'] ) {
  140.                 $string = password_hash($_POST['STRING'], $arrPHPMmethods[$_POST['PHPMethode']] );
  141.                 $output = '<h2>' . $translator -> get('Output') . ':</h2><output id="hash">' . htmlentities( $string ) . '</output>';
  142.         }
  143. }
  144.  
  145. if ( ! empty ( $_POST['PHPOpenSSLMethode'] ) ) {
  146.         if ( isset( $_POST['STRING'] ) and $_POST['STRING'] ) {
  147.                 if ( $PHPOpenSSLbase64 ) {
  148.                         $string = base64_encode( openssl_digest( $_POST['STRING'], $_POST['PHPOpenSSLMethode'], true ) );
  149.                 } else {
  150.                         $string = openssl_digest( $_POST['STRING'], $_POST['PHPOpenSSLMethode'], false );
  151.                 }
  152.                 $output = '<h2>' . $translator -> get('Output') . ':</h2><output id="hash">' . htmlentities( $string ) . '</output>';
  153.         }
  154. }
  155.  
  156. if ( ! empty ( $_POST['UnixOpenSSLMethode'] ) ) {
  157.         if ( isset( $_POST['STRING'] ) and $_POST['STRING'] ) {
  158.                 $string = getOpenSSLHash( $_POST['STRING'], $_POST['UnixOpenSSLMethode'], false );
  159.                 if ( $UnixOpenSSLbase64 ) {
  160.                         $string = base64_encode( hex2bin( $string ) );
  161.                 }
  162.                 $output = '<h2>' . $translator -> get('Output') . ':</h2><output id="hash">' . htmlentities( $string ) . '</output>';
  163.         }
  164. }
  165.  
  166. if ( ! empty( $_POST['CryptMethode'] ) ) {
  167.         if ( isset( $_POST['STRING'] ) and $_POST['STRING'] ) {
  168.                 if ( 'STD_DES' == $_POST['CryptMethode'] ) {
  169.                         $salt = mkSalt( 2 );
  170.                         $string = crypt( $_POST['STRING'], $salt );
  171.                 $output = '<h2>' . $translator -> get('Output') . ':</h2><output id="hash">' . htmlentities( $string ) . '</output>';
  172.         } elseif ( 'EXT_DES' == $_POST['CryptMethode'] )  {
  173.                         $salt = '_' . mkSalt(8 );
  174.                         $string = crypt( $_POST['STRING'], $salt );
  175.                 $output = '<h2>' . $translator -> get('Output') . ':</h2><output id="hash">' . htmlentities( $string ) . '</output>';
  176.                 } elseif ( 'MD5' == $_POST['CryptMethode'] )  {
  177.                         $salt = '$1$' . mkSalt( 9 );
  178.                         $string = crypt( $_POST['STRING'], $salt );
  179.                 $output = '<h2>' . $translator -> get('Output') . ':</h2><output id="hash">' . htmlentities( $string ) . '</output>';
  180.                 } elseif ( 'BLOWFISH-2a' == $_POST['CryptMethode'] )  {
  181.                         $salt = '$2a$10$' . mkSalt();
  182.                         $string = crypt( $_POST['STRING'], $salt );
  183.                 $output = '<h2>' . $translator -> get('Output') . ':</h2><output id="hash">' . htmlentities( $string ) . '</output>';
  184.                 } elseif ( 'BLOWFISH-2x' == $_POST['CryptMethode'] )  {
  185.                         $salt = '$2x$10$' . mkSalt();
  186.                         $string = crypt( $_POST['STRING'], $salt );
  187.                 $output = '<h2>' . $translator -> get('Output') . ':</h2><output id="hash">' . htmlentities( $string ) . '</output>';
  188.                 } elseif ( 'BLOWFISH-2y' == $_POST['CryptMethode'] )  {
  189.                         $salt = '$2y$10$' . mkSalt();
  190.                         $string = crypt( $_POST['STRING'], $salt );
  191.                 $output = '<h2>' . $translator -> get('Output') . ':</h2><output id="hash">' . htmlentities( $string ) . '</output>';
  192.                 } elseif ( 'SHA-256' == $_POST['CryptMethode'] )  {
  193.                         $salt = '$5$rounds=65536$' . mkSalt();
  194.                         $string = crypt( $_POST['STRING'], $salt );
  195.                 $output = '<h2>' . $translator -> get('Output') . ':</h2><output id="hash">' . htmlentities( $string ) . '</output>';
  196.                 } elseif ( 'SHA-512' == $_POST['CryptMethode'] )  {
  197.                         $salt = '$6$rounds=65536$' . mkSalt(22 );
  198.                         $string = crypt( $_POST['STRING'], $salt );
  199.                 $output = '<h2>' . $translator -> get('Output') . ':</h2><output id="hash">' . htmlentities( $string ) . '</output>';
  200.                 }
  201.         }
  202. }
  203.  
  204. if ( ! empty( $_POST['OtherMethode'] ) ) {
  205.         if ( isset( $_POST['STRING'] ) and $_POST['STRING'] ) {
  206.                 if ( 'PHP-md5()' == $_POST['OtherMethode'] ) {
  207.                         $string = md5( $_POST['STRING'] );
  208.                         $output = '<h2>' . $translator -> get('Output') . ':</h2><output id="hash">' . htmlentities( $string ) . '</output>';
  209.                 } elseif ( 'PHP-sha1()' == $_POST['OtherMethode'] ) {
  210.                         $string = sha1( $_POST['STRING'] );
  211.                         $output = '<h2>' . $translator -> get('Output') . ':</h2><output id="hash">' . htmlentities( $string ) . '</output>';
  212.                 } elseif ( 'Old Unix passwd' == $_POST['OtherMethode'] ) {
  213.                         $sys = "openssl 'passwd' " .  escapeshellarg( $_POST['STRING'] );
  214.                         $output = '<h2>' . $translator -> get('Output') . ':</h2><output id="hash">' . htmlentities( `$sys` ) . '</output>';
  215.                 } elseif  ( 'Old Unix passwd ($1$)' == $_POST['OtherMethode'] ) {
  216.                         $salt = mkSalt( 3 );
  217.                         $sys = 'openssl passwd -1 -salt ' . escapeshellarg( $salt ) . ' ' . escapeshellarg( $_POST['STRING'] );
  218.                         $output = '<h2>' . $translator -> get('Output') . ':</h2><output id="hash">' . htmlentities( `$sys` ) . '</output>';
  219.                 } elseif  ( 'Old Apache <= 2.2' == $_POST['OtherMethode'] ) {
  220.                         $h = new APR1_MD5();
  221.                         $string = $h -> hash( $_POST['STRING'] );
  222.                         $output = '<h2>' . $translator -> get('Output') . ':</h2><output id="hash">' . $string . '</output>';
  223.                 } elseif  ( 'Apache > 2.2' == $_POST['OtherMethode'] ) {
  224.                         $salt = '$2y$05$' . mkSalt();
  225.                         $string = crypt( $_POST['STRING'], $salt );
  226.                         $output = '<h2>' . $translator -> get('Output') . ':</h2><output id="hash">' . htmlentities( $string ) . '</output>';
  227.                 } elseif  ( 'Old MySQL-passwd()' == $_POST['OtherMethode'] ) {
  228.                         $string = '*' . strtoupper( sha1( sha1( $_POST['STRING'], TRUE ) ) );
  229.                         $output = '<h2>' . $translator -> get('Output') . ':</h2><output id="hash">' . htmlentities( $string ) . '</output>';
  230.                 } else {
  231.                         trigger_error("Methode: " . $_POST['OtherMethode'], E_USER_WARNING );
  232.                 }
  233.         }
  234. }
  235.  
  236. class APR1_MD5 {
  237.     const BASE64_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  238.     const APRMD5_ALPHABET = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  239.     // Source/References for core algorithm:
  240.     // http://www.cryptologie.net/article/126/bruteforce-apr1-hashes/
  241.     // http://svn.apache.org/viewvc/apr/apr-util/branches/1.3.x/crypto/apr_md5.c?view=co
  242.     // http://www.php.net/manual/en/function.crypt.php#73619
  243.     // http://httpd.apache.org/docs/2.2/misc/password_encryptions.html
  244.     // Wikipedia
  245.     public static function hash($mdp, $salt = null) {
  246.         if (is_null($salt))
  247.             $salt = self::salt();
  248.         $salt = substr($salt, 0, 8);
  249.         $max = strlen($mdp);
  250.         $context = $mdp.'$apr1$'.$salt;
  251.         $binary = pack('H32', md5($mdp.$salt.$mdp));
  252.         for($i=$max; $i>0; $i-=16)
  253.             $context .= substr($binary, 0, min(16, $i));
  254.         for($i=$max; $i>0; $i>>=1)
  255.             $context .= ($i & 1) ? chr(0) : $mdp[0];
  256.         $binary = pack('H32', md5($context));
  257.         for($i=0; $i<1000; $i++) {
  258.             $new = ($i & 1) ? $mdp : $binary;
  259.             if($i % 3) $new .= $salt;
  260.             if($i % 7) $new .= $mdp;
  261.             $new .= ($i & 1) ? $binary : $mdp;
  262.             $binary = pack('H32', md5($new));
  263.         }
  264.         $hash = '';
  265.         for ($i = 0; $i < 5; $i++) {
  266.             $k = $i+6;
  267.             $j = $i+12;
  268.             if($j == 16) $j = 5;
  269.             $hash = $binary[$i].$binary[$k].$binary[$j].$hash;
  270.         }
  271.         $hash = chr(0).chr(0).$binary[11].$hash;
  272.         $hash = strtr(
  273.             strrev(substr(base64_encode($hash), 2)),
  274.             self::BASE64_ALPHABET,
  275.             self::APRMD5_ALPHABET
  276.         );
  277.         return '$apr1$' . $salt . '$'. $hash;
  278.     }
  279.     // 8 character salts are the best. Don't encourage anything but the best.
  280.     public static function salt() {
  281.         $alphabet = self::APRMD5_ALPHABET;
  282.         $salt = '';
  283.         for($i=0; $i<8; $i++) {
  284.             $offset = hexdec(bin2hex(openssl_random_pseudo_bytes(1))) % 64;
  285.             $salt .= $alphabet[$offset];
  286.         }
  287.         return $salt;
  288.     }
  289. }
  290.  
  291. class i10n {
  292.         private $arr;
  293.         private $lang = 'de';
  294.  
  295.         function __construct() {
  296.  
  297.                 if ( isset( $_COOKIE['lang'] ) ) {
  298.                         $this-> lang = $_COOKIE['lang'];
  299.                 } else {
  300.                         if ( isset ( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ) {
  301.                                 $arTmp = explode( ',' , $_SERVER['HTTP_ACCEPT_LANGUAGE'] );
  302.                                 foreach ( $arTmp as $item ) {
  303.                                         $arLangQuote = array();
  304.                                         $arLangQuote = explode( ';', $item );
  305.                                         if ( ! isset($arLangQuote[1] ) ) {
  306.                                                 $arLangQuote[1] = 1;
  307.                                         }
  308.                                         $arLangQuote[0] = trim( $arLangQuote[0] );
  309.                                         if ( $arLangQuote[0] ) {
  310.                                                 $arT['quote'] = floatval( trim( str_replace( 'q=', '', $arLangQuote[1] ) ) );
  311.                                                 $arT['lang']  = trim( strtolower( $arLangQuote[0] ) );
  312.                                                 $arAcceptedLanguages[] = $arT;
  313.                                         }
  314.                                 }
  315.                                 $quote = 0;
  316.                                 $lang='';
  317.                                 foreach ( $arAcceptedLanguages as $l ) {
  318.                                         if ( $l['quote'] > $quote ) {
  319.                                                 $quote = $l['quote'];
  320.                                                 $lang = $l['lang'];
  321.                                         }
  322.                                 }
  323.                         } else {
  324.                                 $this-> lang = 'en';
  325.                         }
  326.                 }
  327.  
  328.                 $s = 'Password hash generator';
  329.                 $this -> arr[$s]['de'] = 'Passwort-Hash-Generator';
  330.                 $this -> arr[$s]['fr'] = 'Password-hash generateur';
  331.  
  332.                 $s = 'This website contains a comprehensive form. Javascript is required for this to work.';
  333.                 $this -> arr[$s]['de'] = 'Diese Webseite enthält ein umfangreiches Formular. Damit dieses bedienbar ist wird Javascript benötigt.';
  334.                 $this -> arr[$s]['fr'] = 'Ce site contient un formulaire complet. Javascript est requis pour que cela fonctionne.';
  335.  
  336.                 $s='Select your language';
  337.                 $this -> arr[$s]['de'] = 'Wählen Sie Ihre Sprache';
  338.                 $this -> arr[$s]['fr'] = 'Sélectioné votre language';
  339.  
  340.                 $s='Please choose the method first';
  341.                 $this -> arr[$s]['de'] = 'Bitte wählen Sie erst die Methode';
  342.                 $this -> arr[$s]['fr'] = 'S\'il vous plaît choisir la méthode d\'abord';
  343.  
  344.                 $s = 'With this tool you can generate password hashes for different systems. This is useful if you forget a password but can access the appropriate files.';
  345.                 $this -> arr[$s]['de'] = 'Mit diesem Tool können Sie Passwort-Hashes für verschiedene Systeme generieren. Das dann nützlich, wenn man ein Passwort ein vergesssen hat aber auf die passenden Dateien schreiben zugreifen kann.';
  346.                 $this -> arr[$s]['fr'] = 'Avec cet outil, vous pouvez générer des hachages de mots de passe pour différents systèmes. Ceci est utile si vous oubliez un mot de passe mais pouvez accéder aux fichiers appropriés.';
  347.  
  348.                 $s = 'Data protection';
  349.                 $this -> arr[$s]['de'] = 'Datenschutz';
  350.                 $this -> arr[$s]['fr'] = 'Politique de confidentialité';
  351.  
  352.                 $s = 'Your IP address will be stored for a maximum of 2 weeks. A cookie is only set if you choose a language. When the browser is finished it will be forgotten. The data entered by you are processed but not stored at all.';
  353.                 $this -> arr[$s]['de'] = 'Ihre IP-Adresse wird höchstens 2 Wochen gespeichert. Ein Cookie wird nur gesetzt wenn Sie eine Sprache wählen. Bei Beendigung des Browsers wird es vergessen. Die von Ihnen eingegeben Daten werden zwar verarbeitet aber gar nicht gespeichert.';
  354.                 $this -> arr[$s]['fr'] = 'Votre adresse IP sera enregistrée pendant 2 semaines maximum. Un cookie n\'est défini que si vous choisissez une langue. Lorsque le navigateur est terminé, il sera oublié. Les données que vous avez entrées sont traitées mais pas stockées du tout.';
  355.  
  356.                 $s = 'You can also <a href="https://code.fastix.org/Projekte/PHP%3Apassword-hash-generator/">download this script</a> and install it yourself.';
  357.                 $this -> arr[$s]['de'] = 'Sie können <a href="https://code.fastix.org/Projekte/PHP%3Apassword-hash-generator/">dieses Skript auch herunterladen</a> und selbst installieren.';
  358.                 $this -> arr[$s]['fr'] = 'Vous pouvez également <a href="https://code.fastix.org/Projekte/PHP%3Apassword-hash-generator/">télécharger ce script</a> et l\'installer vous-même.';
  359.  
  360.                 $s = 'Select the method';
  361.                 $this -> arr[$s]['de'] = 'Auswahl der Methode';
  362.                 $this -> arr[$s]['fr'] = 'Sélectioné de la méthode';
  363.  
  364.                 $s = 'Selection of the algorithm';
  365.                 $this -> arr[$s]['de'] = 'Auswahl des Algorithmus';
  366.                 $this -> arr[$s]['fr'] = 'Sélection de l\'algorithme';
  367.  
  368.                 $s = 'PHP-password_hash()-methods';
  369.                 $this -> arr[$s]['de'] = 'PHP-password_hash()-Methoden';
  370.                 $this -> arr[$s]['fr'] = 'Le methods de PHP-password_hash()';
  371.  
  372.                 $s = 'PHP-crypt()-methods';
  373.                 $this -> arr[$s]['de'] = 'PHP-crypt()-Methoden';
  374.                 $this -> arr[$s]['fr'] = 'Le methods de PHP-crypt()';
  375.  
  376.                 $s = 'PHP-openssl_digest() and output translating';
  377.                 $this -> arr[$s]['de'] = 'PHP-OpenSSL-Methoden / Ausgabe-Form';
  378.                 $this -> arr[$s]['fr'] = 'Le methods de PHP-OpenSSL et procédé d\'émission';
  379.  
  380.                 $s = 'Unix-openssl_digest() and output translating';
  381.                 $this -> arr[$s]['de'] = 'Unix-OpenSSL-Methoden / Ausgabe-Form';
  382.                 $this -> arr[$s]['fr'] = 'Le methods de Unix-OpenSSL et procédé d\'émission';
  383.  
  384.                 $s = 'Other Methods';
  385.                 $this -> arr[$s]['de'] = 'Andere Methoden';
  386.                 $this -> arr[$s]['fr'] = 'Autres méthodes';
  387.  
  388.                 $s = 'None of them';
  389.                 $this -> arr[$s]['de'] = 'Keine davon';
  390.                 $this -> arr[$s]['fr'] = 'Rien de ça';
  391.  
  392.                 $s = 'Enter the password';
  393.                 $this -> arr[$s]['de'] = 'Eingabe des Passwortes';
  394.                 $this -> arr[$s]['fr'] = 'Entrez le mot de passe';
  395.  
  396.                 $s = 'Password';
  397.                 $this -> arr[$s]['de'] = 'Passwort';
  398.                 $this -> arr[$s]['fr'] = 'Le mot de passe';
  399.  
  400.                 $s = 'Generate';
  401.                 $this -> arr[$s]['de'] = 'Generiere';
  402.                 $this -> arr[$s]['fr'] = 'générer';
  403.  
  404.                 $s = 'Output';
  405.                 $this -> arr[$s]['de'] = 'Ausgabe';
  406.                 $this -> arr[$s]['fr'] = 'Résultat';
  407.  
  408.                 $s = 'Remove all <q>white spaces</q> at begin an end of this string';
  409.                 $this -> arr[$s]['de'] = 'Entferne alle <q>white spaces</q> am Beginn und am Ende';
  410.                 $this -> arr[$s]['fr'] = 'Supprimer tous les <q>espaces blancs</q> au début et à la fin';
  411.     }
  412.  
  413.     public function get( $s ) {
  414.                 if ( isset($this -> arr[ $s ][ $this -> lang ] ) ) {
  415.                     return      $this -> arr[ $s ][ $this -> lang ];
  416.                 } else {
  417.                         return $s;
  418.                 }
  419.         }
  420. }
  421.  
  422. function mksalt($l=22, $s='0123456789abcdefghijklmnopqrstyuvwxyzABCDEFGHIJKLMNOPQRSTYUVWXYZ./') {
  423.                 $salt = '';
  424.                 $len = strlen( $s );
  425.                 for ( $i=0; $i<$l; $i++ ) {
  426.                         $p = random_int( 0, $len - 1 );
  427.                         $salt .= $s[$p];
  428.                 }
  429.                 return $salt;
  430. }
  431.  
  432. function getOpenSSLDigests() {
  433.         $rows = explode("\n", `openssl help 2>&1`);
  434.         $firstLine = false;
  435.         $lastLine  = false;
  436.         for ( $i = 0; $i < sizeof( $rows ); $i++ ) {
  437.                 $row = trim( $rows[$i] );
  438.                 if ( false === $firstLine and false !== strpos( $row,  'Message Digest commands' ) ) {
  439.                         $firstLine = $i + 1;
  440.                 }
  441.                 if ( false != $firstLine and '' == $row ) {
  442.                         $lastLine = $i - 1;
  443.                         break;
  444.                 }
  445.         }
  446.  
  447.         if ( 0 == $firstLine ) return false;
  448.  
  449.         $s = "";
  450.         for ( $i = $firstLine; $i <= $lastLine; $i++ ) {
  451.                 $s .= $rows[$i] . " ";
  452.         }
  453.         $s = preg_replace("/\s+/", "\n" , $s );
  454.     $arr = explode( "\n", trim( $s ) );
  455.  
  456.     return $arr;
  457. }
  458.  
  459. function getOpenSSLHash( $string, $digest ) {
  460.         $sys = 'export LANG=en_US.UTF-8; echo -n ' . escapeshellarg( $string ) . ' | openssl ' . escapeshellarg( $digest );
  461.         return trim( substr(`$sys`, 9 ) );
  462. }
  463.  
  464. function getOldUnixPasswordHash ( $string ) {
  465.     $sys = 'export LANG=en_US.UTF-8; echo ' . escapeshellarg( $string ) . ' | openssl passwd stdin';
  466.     return trim(`$sys`);
  467. }
  468.  
  469. ?><!DOCTYPE html>
  470. <html>
  471. <head>
  472.         <title><?=$translator -> get('Password hash generator'); ?></title>
  473.         <link rel="stylesheet" href="/standard.css" type="text/css">
  474. <style>
  475. #content { padding: 0rem 1rem 0rem 1rem; }
  476. fieldset { margin-bottom:1rem; }
  477. legend   { font-weight:bold; }
  478. output   { border:1px solid black; padding: .5rem; }
  479. #STRING  { width: calc(100% - 3rem); }
  480. #languageSselector { position:absolute;top:.75rem; right:1rem; text-align:right; }
  481. </style>
  482. <script>
  483.  
  484. function fShow(formPart) {
  485.   document.getElementById('selectedMethod').innerHTML=document.getElementById(formPart).innerHTML;
  486.   clearHash();
  487. }
  488.  
  489. function clearHash() {
  490.         if ( document.getElementById('hash') ) {
  491.                 document.getElementById('hash').innerHTML='';
  492.         }
  493. }
  494.  
  495. </script>
  496. </head>
  497. <header>
  498. <h1><?=$translator -> get('Password hash generator'); ?></h1>
  499. </header>
  500. <noscript><strong>Hm. <?=$translator -> get('This website contains a comprehensive form. Javascript is required for this to work.');?></strong></noscript>
  501. <div id="content" style="display:none">
  502. <p><?=$translator -> get('With this tool you can generate password hashes for different systems. This is useful if you forget a password but can access the appropriate files.'); ?></p>
  503. <p><strong><?=$translator -> get('Data protection');?>:</strong> <?=$translator -> get('Your IP address will be stored for a maximum of 2 weeks. A cookie is only set if you choose a language. When the browser is finished it will be forgotten. The data entered by you are processed but not stored at all.');?> <?=$translator -> get('You can also <a href="https://code.fastix.org/Projekte/PHP%3Apassword-hash-generator/">download this script</a> and install it yourself.'); ?></p>
  504. <div id="languageSselector"><?=$translator -> get('Select your language'); ?>:
  505. <button onclick="document.cookie='lang=en'; location.reload()">en</button>
  506. <button onclick="document.cookie='lang=de'; location.reload()">de</button>
  507. <button onclick="document.cookie='lang=fr'; location.reload()">fr</button>
  508. </div>
  509. <h2>1. <?=$translator -> get('Select the method'); ?></h2>
  510. <button onclick="fShow('selectorPHP'); return false"><?=$translator -> get('PHP-password_hash()-methods') ;?></button>
  511. <button onclick="fShow('selectorCrypt'); return false"><?=$translator -> get('PHP-crypt()-methods') ;?></button>
  512. <button onclick="fShow('selectorPHPOpenSSL'); return false"><?=$translator -> get('PHP-openssl_digest() and output translating') ;?></button>
  513. <button onclick="fShow('selectorUnixOpenSSL'); return false"><?=$translator -> get('Unix-openssl_digest() and output translating') ;?></button>
  514. <button onclick="fShow('selectorOthers'); return false"><?=$translator -> get('Other Methods') ;?></button>
  515. <form name="methods" method="POST">
  516. <h2>2. <?=$translator -> get('Selection of the algorithm'); ?>:</h2>
  517.  
  518.  
  519. <fieldset id="selectedMethod">
  520. <?php
  521. if ( isset($_POST['PHPMethode'] ) ) {
  522.         echo $selectorPHP;
  523. } elseif ( isset($_POST['CryptMethode'] ) ) {
  524.         echo $selectorCrypt;
  525. } elseif ( isset($_POST['PHPOpenSSLMethode'] ) ) {
  526.         echo $selectorPHPOpenSSL;
  527. } elseif ( isset($_POST['UnixOpenSSLMethode'] ) ) {
  528.         echo $selectorUnixOpenSSL;
  529. } elseif ( isset($_POST['OtherMethode'] ) ) {
  530.         echo $selectorOther;
  531. } else {
  532.         echo '<p>' . $translator -> get('Please choose the method first') . '</p>';
  533. }
  534. ?>
  535. </fieldset>
  536.  
  537. <h2>3. <?=$translator -> get('Enter the password'); ?>:</h2>
  538. <fieldset>
  539.         <legend for="STRING"><?=$translator -> get('Password'); ?>:</legend>
  540.         <input oninput="clearHash();" onkeydown="clearHash();" onchange="clearHash();" type="text" id="STRING" name="STRING" value="<?=htmlspecialchars( $_POST['STRING'] );?>"><br>
  541. <?php if (! empty( $_POST['trimString'] ) ) { ?>
  542.         <input onchange="clearHash();" type="checkbox" checked="checked" name="trimString"> <?=$translator -> get('Remove all <q>white spaces</q> at begin an end of this string'); ?>
  543. <?php } else { ?>
  544.         <input onchange="clearHash();" type="checkbox" name="trimString"> <?=$translator -> get('Remove all <q>white spaces</q> at begin an end of this string'); ?>
  545. <?php } ?>
  546. </fieldset>
  547. <button onclick="clearHash()"><?=$translator -> get('Generate'); ?></button>
  548. <?=$output; ?>
  549. </form>
  550. </div>
  551.  
  552. <form id="hiddenFormParts" style="display:none;">
  553. <div id="selectorPHP">
  554.         <?=$selectorPHP; ?>
  555. </div>
  556.  
  557. <div id="selectorCrypt">
  558.         <?=$selectorCrypt; ?>
  559. </div>
  560.  
  561. <div id="selectorPHPOpenSSL">
  562.         <?=$selectorPHPOpenSSL; ?>
  563. </div>
  564.  
  565. <div id="selectorUnixOpenSSL">
  566.     <?=$selectorUnixOpenSSL; ?>
  567. </div>
  568.  
  569. <div id="selectorOthers">
  570.         <?=$selectorOther; ?>
  571. </div>
  572. </form>
  573.  
  574. </div>
  575. <script>
  576. document.getElementById('content').style.display="block";
  577. </script>
  578. </body>
  579. </html>