Multiple password script

Hello, I was wondering if anyone here would know how to make this script work with multiple passwords?

[php]<?php

/* Config Section */

$pass = ‘password’; // Set the password.
$cookiename = ‘sascookie’; // Optional change: Give the cookie a name. Default is sascookie
$expirytime = time()+3600; // Optional change: Set an expiry time for the password (in seconds). Default is 1 hour.
$msg = ‘Password incorrect.’; // Optional change: Error message displayed when password is incorrect. Default is “Password incorrect”.

/* End Config */

/* Logout Stuff - Sept 5, 2005 */

if (isset($_REQUEST[‘logout’])) {
setcookie($cookiename,’’,time() - 3600); // remove cookie/password
if (substr($_SERVER[‘REQUEST_URI’],-12)==’?logout=true’) { // if there is ‘?logout=true’ in the URL
$url=str_replace(’?logout=true’,’’,$_SERVER[‘REQUEST_URI’]); // remove the string ‘?logout=true’ from the URL
header(‘Location: ‘.$url); // redirect the browser to original URL
}
show_login_page(’’);
exit();
}

$logout_button=’’;
$logout_text=‘Logout’;

/* End Logout Stuff */

/* FUNCTIONS */
$encrypt_pass=md5($pass); // encrypt password

function setmycookie() {
global $cookiename,$encrypt_pass,$expirytime;
setcookie($cookiename,$encrypt_pass,$expirytime);
}

function show_login_page($msg) {
?>

Authorization Required
Authorization Required<>

Please enter the password below Use "demo" to login. Use a wrong password to see the error message.

	<p>Once logged in, you won't need to re-enter the password for one hour, the expiry time can be customized to your liking by altering the variable $expirytime in the Config Section of sas.php.</p>


	<p>You will need to enable cookies for SAS to work as expected.</p>
	
	<form action="" method="POST">
		Password:&nbsp;<input type="password" name="password" size="20">&nbsp;
		<input type="submit" value="Login">
		<input type="hidden" name="sub" value="sub">
	</form>
	<div class=error><?=$msg?><>
<>

<>
<>

Authentication by Simple Authorization Script Copyright © 2005.<> <? }

/* END FUNCTIONS */

$errormsg=’’;
if (substr($_SERVER[‘REQUEST_URI’],-7)!=‘sas.php’) {// if someone tries to request sas.php
if (isset($_POST[‘sub’])) { // if form has been submitted
$submitted_pass=md5($_POST[‘password’]); // encrypt submitted password
if ($submitted_pass<>$encrypt_pass) { // if password is incorrect
$errormsg=$msg;
show_login_page($errormsg);
exit();
} else { // if password is correct
setmycookie();
}
} else {
if (isset($_COOKIE[$cookiename])) { // if cookie isset
if ($_COOKIE[$cookiename]==$encrypt_pass) { // if cookie is correct
// do nothing
} else { // if cookie is incorrect
show_login_page($errormsg);
exit();
}
} else { // if cookie is not set
show_login_page($errormsg);
exit();
}
}
} else {
echo ‘Try requesting demo.php’;
}
?>
[/php]

That’s the whole script.

Also if anyone know of any other script that will do just that(protect page using multiple passwords) I’d appreciate it very much. I’ve been looking for something similar and this is the closest I found.

Thanks in advance!

Sponsor our Newsletter | Privacy Policy | Terms of Service