<?php

/**
 * @file obfuscater_password.php
 * @brief Page qui permet d'obfuscater un password dans une page PHP
 *
 * @author hughes monget
 * @see http://monget.com/
 */

define('PARAM_HTTP_PASSWORD''p');
define('PARAM_HTTP_ACTION''a');

$str_password '';

$bool_action = isset($_REQUEST[PARAM_HTTP_ACTION]) && isset($_REQUEST[PARAM_HTTP_PASSWORD]) && is_string($_REQUEST[PARAM_HTTP_PASSWORD]);

if (
$bool_action)
{
    
$str_password $_REQUEST[PARAM_HTTP_PASSWORD];
    if (
get_magic_quotes_gpc())
    {
        
$str_password stripslashes($str_password);
    }

    
$str_aleas array_merge(range('0''9'), range('a''z'), range('A''Z'));
    
shuffle($str_aleas);
    
$str_aleas implode(''$str_aleas);
    
$str_padding substr($str_aleas0strlen($str_password));
    
$str_encode base64_encode($str_password $str_padding);
}

?>
<!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>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
        <title>Obfuscater un password</title>
        <style type="text/css">
        <!--
        body *
        {
            font-family: monospace;
            font-size: 8pt;
        }

        input.submit
        {
            width: 100px;
            display: block;
        }

        input.eval
        {
            width: 600px;
        }

        -->
        </style>
        <script type="text/javascript">
        <!--;
            function on_load()
            {
                if (document && document.getElementById)
                {
                    var obj_pattern = document.getElementById('<?php echo PARAM_HTTP_PASSWORD ?>');
                    if (obj_pattern && obj_pattern.focus)
                    {
                        obj_pattern.focus();
                    }
                }
            }

        //-->
        </script>
    </head>
    <body onload="on_load();">
        <form method="post">
            <input type="text" name="<?php echo PARAM_HTTP_PASSWORD ?>" value="<?php echo htmlspecialchars($str_password?>" />
            <input type="submit" name="<?php echo PARAM_HTTP_ACTION ?>" class="submit" value="Obfuscater" />
        </form>
<?php
if ($bool_action)
{
    echo 
'<pre>';
    echo 
'padding : ',htmlspecialchars($str_padding),'<br/>';
    echo 
'encode  : ',htmlspecialchars($str_encode),'<br/>';
    
$str_eval '$str_password = base64_decode(\''.$str_encode.'\') ^ \''.$str_padding.'\';';
    echo 
'php code: <input class="eval" type="text" readonly="readonly" value="',htmlspecialchars($str_eval),'" onclick="if (this && this.select) { this.select() ;} " /><br/>';
    eval(
$str_eval);
    echo 
'eval    : ',htmlspecialchars($str_password);
    echo 
'</pre>';
}

echo 
'<hr />';
highlight_file(__FILE__);

?>
    </body>
</html>