Código PHP:
<?php
////////////////////////////////////////////////////////
// .htpasswd Maker v1.0 - sebflipper Copyright 2004 //
// http://www.sebflipper.com //
// //
// This script will generate an encrypted password //
// for .htpasswd and .htaccess files //
////////////////////////////////////////////////////////
?>
<HTML>
<HEAD>
<TITLE>.htpasswd Maker</TITLE>
<style type="text/css">
<!--
body {
font-family: Arial, Helvetica, sans-serif;
font-size: x-small;
}
table {
font-size: x-small;
}
-->
</style>
</HEAD>
<BODY>
<?
if ( isset($_POST[user]) && isset($_POST[password1]))
{
if( $_POST[password1] == $_POST[password2] )
{
/*$pfad = $DOCUMENT_ROOT . dirname($PHP_SELF) . "/.htpasswd";
$safe= dirname ($PHPSELF);
$htaccess_text = "AuthType Basic\n".
"AuthName \"\"\n".
"AuthUserFile $pfad\n".
"require valid-user\n";*/
$user = $_POST[user];
$password1 = $_POST[password1];
for ($i = 0; $i < count ($user); $i++)
{
$htpasswd_text .= "$user[$i]:".crypt($password1[$i],CRYPT_STD_DES)."";
}
echo "First make a file called .htaccess put this in it:<br><br>
AuthName \"Password Protected Directory\"<br>
AuthType Basic<br>
AuthUserFile /your/server/path/.htpasswd<br>
require valid-user<br><br>
Then make a file called .htpasswd. Below is the text you need to enter into your .htpasswd file, then upload both the file to the directory you want to protect!";
echo "<p><hr></p>";
echo nl2br($htpasswd_text);
echo "<p><hr></p>";
}
else
{
echo "<p><hr></p>";
echo "<b>Passwords do not match</b>";
echo "<p><hr></p>";
}
}
?>
<script language="javascript">
<!--
function ValidateForm() {
for (i = 0; i < document.forms[0].elements.length; i++) {
if (document.forms[0].elements[i].value == "") {
switch (document.forms[0].elements[i].type) {
case "text":
alert('Please complete all fields before submitting');
document.all.submit.style.visibility='visible';
return false;
break;
case "textarea":
alert('Please complete all fields before submitting');
document.all.submit.style.visibility='visible';
return false;
break;
case "file":
alert('Please complete all fields before submitting');
document.all.submit.style.visibility='visible';
return false;
break;
}
}
}
return true;
}
//-->
</script>
<FORM METHOD="POST" ACTION="<? echo $PHP_SELF; ?>" onSubmit='return ValidateForm()'>
<table>
<tr><td>Username:</td><td><INPUT TYPE="TEXT" NAME="user[]"></td></tr>
<tr><td>Password:</td><td><INPUT TYPE="PASSWORD" NAME="password1[]"></td></tr>
<tr><td>Password again:</td><td><INPUT TYPE="PASSWORD" NAME="password2[]"></td></tr>
<tr><td><center><INPUT type=submit name="submit" VALUE="Encrypt" onclick="document.all.submit.style.visibility='hidden'">
</FORM>
</center></td></tr>
</table>
<p>Note: We do NOT store your usernames and passwords.</p>
<p>.htpasswd Maker v1.2 designed by <a href="http://www.sebflipper.com" target="_blank">Seb Flipper</a></p>
</BODY>
</HTML>