Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[PHP].htpasswd&.htaccess generator?

Experienced Elementalist
Joined
Apr 15, 2008
Messages
256
Reaction score
0
PHP:
<HTML>
<HEAD>
<?php
rename(".htaccess.txt", ".htaccess");
rename(".htpasswd.txt",".htpasswd");
chmod(".htaccess", 0777);
chmod(".htpasswd, 0777);
?>

<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 .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> </p>
</BODY>
</HTML>
Im trying to create a script that will automatically create a .htpasswd and .htaccess files for me in the :
../$admin/ directory
someone help please?
How would you write the username's &passwords' to the .htpasswd and .htaccess files?
 
Custom Title Activated
Loyal Member
Joined
Jun 28, 2007
Messages
2,986
Reaction score
3
I believe they are encrypted, you should add passwords through cPanel really...

.htaccess doesn't hold passwords, and I'm quite sure .htpasswd is write protected and unaccessable, it's outside your www directory.
 
Experienced Elementalist
Joined
Apr 15, 2008
Messages
256
Reaction score
0
I believe they are encrypted, you should add passwords through cPanel really...

.htaccess doesn't hold passwords, and I'm quite sure .htpasswd is write protected and unaccessable, it's outside your www directory.
They are encrypted, and no you don't need cpanel to make them at all. It's for my cms and stuff.
I'll google some more stuff.
 
Back
Top