<?php

    
include('MyFuncations.php');                        //    Include the fuctions that are needed to make this page work.
    
SendHeaders();

    
$phpself        =    @$_SERVER["PHP_SELF"];
    
$QueryString    =    @$_SERVER["QUERY_STRING"];
    if(
"view-source" == $QueryString)    {    show_source("./".$phpself);    exit;    }
    if(
"sourcecode" == $QueryString)    {    show_source(@$_SERVER["SCRIPT_FILENAME"]);    exit;    }
?><!DOCTYPE html>
<?php
// Password to be encrypted for a .htpasswd file
// Encrypt password
$Username="";
$clearTextPassword="";

if (
$_SERVER["REQUEST_METHOD"] == "POST") {
  if (empty(
$_POST["Username"]))    {    $Username="UserName";    }
    else                            {    
$Username $_POST["Username"];    }
  if (empty(
$_POST["Password"]))    {    $clearTextPassword 'some password';    }
    else                            {    
$clearTextPassword $_POST["Password"];    }
}

$password htpasswd($clearTextPassword);
$bannercolor "blue";

    
$httphost        =     @$_SERVER["HTTP_HOST"];

?>
<html lang="en">
<head>
    <?php    {   include('GoogleAnalytics.php');   }  ?>
    <title>Htpasswd Generator – Create htpasswd | NetworkStuff . net</title>
    <?php    include('head-for-bootstrap_fa.php');    ?>
    <style>
        body        {    text-align:center;    }
        body        {    color:silver;            font-family:"Trebuchet MS", Arial, Helvetica;    }
        i            {    color:darkorange;    font-weight:600    }
    </style>
</head>
<body>
<?php    include('header.php');    ?>
<div class="container container-fluid">

<h1>Htpasswd Generator</h1>

<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" class="form-inline">
    <div class="container col-4">
      <form class="form-signin">
        <h2 class="form-signin-heading">Create htpasswd</h2>
        <div class="form-group row">
            <div class="input-group-prepend col-sm-4">
                <span class="input-group-text">Username</span>
            </div>
            <input class="form-control col-sm-8" placeholder="Enter Username" type="text" name="Username" value="<?php echo $Username;?>" required>
        </div>
        <div class="form-group row">
            <div class="input-group-prepend col-sm-4">
                <span class="input-group-text">Password:</span>
            </div>
            <input class="form-control col-sm-8" placeholder="Enter Password" type="text" name="Password" value="<?php echo $clearTextPassword;?>" required>
        </div>
        <button class="btn btn-lg btn-success btn-block" type="submit">Generate .htpasswd entry</button>
      </form>
    </div> <!-- /container -->    
</form>
<h3>Create a file called .htpasswd</h3>
<h4>Add the following line:</h4>

<?php
// Print encrypted password
echo "<p class=\"alert alert-primary offset-sm-4 col-sm-4\"><tt>$Username:$password</tt>    <code class=\"text-muted\">    ##    $clearTextPassword</code></p>";
//    echo "[".base64_decode($password)."]";
?>

<h5>Excluding the mute text starting with "##".
<h6>...</h6>
<?php

/*    Functions    */        //    Below here our my 'subroutes'.

function htpasswd($clearTextPassword)    {
    
$password crypt($clearTextPasswordbase64_encode($clearTextPassword));
    return 
$password;
}

?>
<hr>

<?php    include('copyright.php');    ?>

</div>

<?php    /*        ### SPECIAL CRYPT Functions    ###

// 2 character salt
if (CRYPT_STD_DES == 1)    {    echo "Standard DES: ".crypt('something','st')."\n<br>";     }
    else                {    echo "Standard DES not supported.\n<br>";    }

// 4 character salt
if (CRYPT_EXT_DES == 1)    {    echo "Extended DES: ".crypt('something','_S4..some')."\n<br>";    }
    else                {    echo "Extended DES not supported.\n<br>";    }

// 12 character salt starting with $1$ 
if (CRYPT_MD5 == 1)        {    echo "MD5: ".crypt('something','$1$somethin$')."\n<br>";     }
    else                {    echo "MD5 not supported.\n<br>";    }

// Salt starting with $2a$. The two digit cost parameter: 09. 22 characters 
if (CRYPT_BLOWFISH == 1){    echo "Blowfish: ".crypt('something','$2a$09$anexamplestringforsalt$')."\n<br>";     }
    else                {    echo "Blowfish DES not supported.\n<br>";    }

// 16 character salt starting with $5$. The default number of rounds is 5000.
if (CRYPT_SHA256 == 1)    {    echo "SHA-256: ".crypt('something','$5$rounds=5000$anexamplestringforsalt$')."\n<br>"; }
    else                {    echo "SHA-256 not supported.\n<br>";    }

// 16 character salt starting with $6$. The default number of rounds is 5000.
if (CRYPT_SHA512 == 1)    {    echo "SHA-512: ".crypt('something','$6$rounds=5000$anexamplestringforsalt$');     }
    else                {    echo "SHA-512 not supported.";    }

*/
        
include('footer.php');
?>
    
</body></html>