PASSWORD
CRYPT_STD_DES false
CRYPT_EXT_DES
CRYPT_MD5 false
CRYPT_BLOWFISH
MD5
SHA1
SHA256
CRC32

<?php

/**
 * @file hasher_password.php
 * @brief Ce script va hasher un mot de passe.
 *
 * @author hughes monget
 * @see http://monget.com/
 */

// http://fr.php.net/crypt
//define('AFFICHER_SALT', TRUE);
//define('AFFICHER_DEFAULT', TRUE);

$str_password                     '';
$str_salt                         '';
$str_hash_password_default        '';
$str_hash_password_std_des        '';
$str_hash_password_ext_des        '';
$str_hash_password_crypt_md5      '';
$str_hash_password_crypt_blowfish '';
$str_hash_password_md5            '';
$str_hash_password_sha1           '';
$str_hash_password_sha256         '';
$str_hash_password_crc32          '';

if (isset(
$_REQUEST['password']) && is_string($_REQUEST['password']))
{
    
$str_salt array_merge(range('a''z'), range('A''Z'), range('0''9'));
    
//$str_salt = range(chr(64), chr(126));
    
shuffle($str_salt);
    
$str_salt implode($str_salt);

    
$str_password = (string) $_GET['password'];
    if (
get_magic_quotes_gpc())
    {
        
$str_password stripslashes($str_password);
    }
    
$str_hash_password_default        crypt($str_password);
    
$str_hash_password_std_des        crypt($str_passwordsubstr($str_salt02));
    
$str_hash_password_ext_des        crypt($str_password'_1000'.substr($str_salt04));
    
//$str_hash_password_ext_des        = crypt($str_password, '_'.substr($str_salt, 0, 8));
    
$str_hash_password_crypt_md5      crypt($str_password'$1$'.substr($str_salt012));
    
$str_hash_password_crypt_blowfish crypt($str_password'$2y$10$'.substr($str_salt022));

    
$str_hash_password_md5            md5($str_password);
    
$str_hash_password_sha1           sha1($str_password);
    
$str_hash_password_sha256         bin2hex(mhash(MHASH_SHA256$str_password));
    
$str_hash_password_crc32          bin2hex(mhash(MHASH_CRC32$str_password));
}

$str_password                     htmlspecialchars($str_password);
$str_salt                         htmlspecialchars($str_salt);
$str_hash_password_default        htmlspecialchars($str_hash_password_default);
$str_hash_password_std_des        htmlspecialchars($str_hash_password_std_des);
$str_hash_password_ext_des        htmlspecialchars($str_hash_password_ext_des);
$str_hash_password_crypt_md5      htmlspecialchars($str_hash_password_crypt_md5);
$str_hash_password_crypt_blowfish htmlspecialchars($str_hash_password_crypt_blowfish);
$str_hash_password_md5            htmlspecialchars($str_hash_password_md5);
$str_hash_password_sha1           htmlspecialchars($str_hash_password_sha1);
$str_hash_password_sha256         htmlspecialchars($str_hash_password_sha256);
$str_hash_password_crc32          htmlspecialchars($str_hash_password_crc32);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
    <head>
        <title>Hashage de password</title>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
        <style type="text/css">
        <!--
        table, input
        {
            border-collapse: collapse;
            font-family: monospace;
        }
        td, th
        {
            border: 1px solid #000;
            padding: 5px 5px;
        }
        th
        {
            text-align: right;
        }
        .password
        {
            width: 400px;
        }
        -->
        </style>
    </head>
    <body>
        <form method="get" action="">
            <table>
                <tr>
                    <th>PASSWORD</th>
                    <td>
                        <input type="text" class="password" id="password" name="password" value="<?php echo $str_password ?>" />
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input type="submit" value="submit" />
                    </td>
                </tr>
<?php
if (defined('AFFICHER_SALT') && constant('AFFICHER_SALT'))
{
?>
                <tr>
                    <th>SALT</th>
                    <td>
                        <input type="text" class="password" readonly="readonly" value="<?php echo $str_salt ?>" onclick="javascript:this.select();" />
                    </td>
                </tr>
<?php
}

if (
defined('AFFICHER_DEFAULT') && constant('AFFICHER_DEFAULT'))
{

?>
                <tr>
                    <th>DEFAULT</th>
                    <td>
                        <input type="text" class="password" readonly="readonly" value="<?php echo $str_hash_password_default ?>" onclick="javascript:this.select();" />
                        <?php var_export($str_hash_password_default === crypt($str_password$str_hash_password_default)) ?>
                    </td>
                </tr>
                </tr>
<?php
}
?>
                <tr>
                    <th>CRYPT_STD_DES</th>
                    <td>
                        <input type="text" class="password" readonly="readonly" value="<?php echo $str_hash_password_std_des ?>" onclick="javascript:this.select();" />
                        <?php var_export($str_hash_password_std_des === crypt($str_password$str_hash_password_std_des)) ?>
                    </td>
                </tr>
<?php
if (CRYPT_EXT_DES)
{
?>
                <tr>
                    <th>CRYPT_EXT_DES</th>
                    <td>
                        <input type="text" class="password" readonly="readonly" value="<?php echo $str_hash_password_ext_des ?>" onclick="javascript:this.select();" />

                    </td>
                </tr>
<?php
}
?>
                <tr>
                    <th>CRYPT_MD5</th>
                    <td>
                        <input type="text" class="password" readonly="readonly" value="<?php echo $str_hash_password_crypt_md5 ?>" onclick="javascript:this.select();" />
                        <?php var_export($str_hash_password_crypt_md5 === crypt($str_password$str_hash_password_crypt_md5)) ?>
                    </td>
                </tr>
<?php
if (OR CRYPT_BLOWFISH)
{
?>
                <tr>
                    <th>CRYPT_BLOWFISH</th>
                    <td>
                        <input type="text" class="password" readonly="readonly" value="<?php echo $str_hash_password_crypt_blowfish ?>" onclick="javascript:this.select();" />
                    </td>
                </tr>
<?php
}
?>
                <tr>
                    <th>MD5</th>
                    <td>
                        <input type="text" class="password" readonly="readonly" value="<?php echo $str_hash_password_md5 ?>" onclick="javascript:this.select();" />
                    </td>
                </tr>
                <tr>
                    <th>SHA1</th>
                    <td>
                        <input type="text" class="password" readonly="readonly" value="<?php echo $str_hash_password_sha1 ?>" onclick="javascript:this.select();" />
                    </td>
                </tr>
                <tr>
                    <th>SHA256</th>
                    <td>
                        <input type="text" class="password" readonly="readonly" value="<?php echo $str_hash_password_sha256 ?>" onclick="javascript:this.select();" />
                    </td>
                </tr>
                <tr>
                    <th>CRC32</th>
                    <td>
                        <input type="text" class="password" readonly="readonly" value="<?php echo $str_hash_password_crc32 ?>" onclick="javascript:this.select();" />
                    </td>
                </tr>
            </table>
        </form>
<?php
echo '<hr />';
highlight_file(__FILE__);
?>
    </body>
</html>