Click to See Complete Forum and Search --> : Password Protection


quizzer
11-27-2002, 03:18 PM
I would like to password protect some directories on my web site so that depending on the user name used they are allowed to view a directory. I understand that .htaccess is proberly the best way to do this, but my web host does not allow .htaccess files on their server. Is there another way of doing this?

Thanks:confused:

Klyve1
11-27-2002, 05:11 PM
What DO they allow? And how secure do you need it?

quizzer
11-28-2002, 06:23 AM
They allow CGI with SSI (Perl4) PHP

They do not allow - ASP - JSP - MySQL - .htaccess files - Java servlets

There is no sensitive information in the directories I want to protect, so security does not need to ultra secure, but I would like to be able to put off the average web user.

Thanks for the interest

Klyve1
11-28-2002, 06:34 AM
In that case a simple php login will do. It's not THE most secure but it'll put off most.

<?php
$login = loginword;
$password = password;

if (isset($form[login]) && isset($form[password])){
if (($login == $form[login]) && ($password == $form[password])){

echo "YOUR HTML GOES HERE IF THEY LOGIN CORRECTLY";

}else{
// If their login is incorrect
echo "<h3 align='center'>Invalid Login</h3>
<br>
<div align='center'><span class='Bold'>As we regularly change the login/password pairs you may <br>
need to request the new ones:
<a href='mailto:doowahdiddy@yourdomain.com'>Password Request</a></div><br>
<br>

<FORM method=post>
<table align='center'>
<tr>
<td><span class='BoldText'>Login</span></td>
<td><span class='BoldText'>Password</span></td>
</tr>
<tr>
<td><input type=text name='form[login]'></td>
<td><input type=password name='form[password]'></td>
</tr>
</table>
<br>
<br>
<div align='center'>
<input type=submit value=Login></div></form>";
}
}else{
// This is what they see first
echo "<h3 align='center'>
Login</h3>
<br>
<form method=post>
<table align='center'>
<tr>
<td><span class='BoldText'>Login</span></td>
<td><span class='BoldText'>Password</span></td>
</tr>
<tr>
<td><input type=text name='form[login]'></td>
<td>
<input type=password name='form[password]'></td>
</tr>
</table>
<br>
<br>
<div align='center'>
<input type=submit value=Login></div></form>";
}
?>
Hope this helps

quizzer
11-28-2002, 06:41 AM
Thanks for the prompt reply I will give this a go later.