Jump to content

SAS script


intakep
 Share

Recommended Posts

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

<?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='<form action="'.$_SERVER['REQUEST_URI'].'" method="post"><input type="submit" name="logout" value="Logout" /></form>';$logout_text='<a href="'.$_SERVER['REQUEST_URI'].'?logout=true">Logout</a>';/* End Logout Stuff *//* FUNCTIONS */$encrypt_pass=md5($pass);	// encrypt passwordfunction setmycookie() {global $cookiename,$encrypt_pass,$expirytime;	setcookie($cookiename,$encrypt_pass,$expirytime);}	function show_login_page($msg) {?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Authorization Required</title><style type="text/css"><!--.error {color:#A80000}body {font:90% Verdana, Arial, sans-serif;color:#404040}#wrapper {width:800px;margin:0 auto;border:1px solid #606060}#main {text-align:center;padding:15px}#header {font:bold 130% Verdana, Arial, sans-serif;color:#DDDDDD;width:100%;height:5em;text-align:center;background:#A80000;line-height:5em}#mid {margin:5em 0 5em 0}#footer {font-size:75%;text-align:center;width:100%}input {border:1px solid #606060; background: #DDDDDD}--></style></head><body><div id="wrapper">	<div id="header">Authorization Required</div><div id="main">	<div id="mid">		<p>Please enter the password below <em>Use "demo" to login. Use a wrong password to see the error message</em>.</p>		<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: <input type="password" name="password" size="20"> 			<input type="submit" value="Login">			<input type="hidden" name="sub" value="sub">		</form>		<div class=error><?=$msg?></div>	</div></div></div><div id="footer">Authentication by <a href="http://www.zann-marketing.com/sas/">Simple Authorization Script</a> Copyright © 2005.</div></body></html><? }/* 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';}?>

This is just a page password protection.I've been searching a lot lately and haven't been able to find anything that worked well. This was the closet, however it only works with one passwords and I'd need several of them.Thanks in advance.

Link to comment
Share on other sites

if you use a DB, you can store all the passwords in a table and just check the users password against the records stored in the passwords table.for this case, you could just create an array of passwords and iterate through the array when it comes to time check the password.

Edited by thescientist
Link to comment
Share on other sites

uhh... which one?either way there are tutorials for both. why not read up on them? it would be more helpful to us than just saying "I don't know" if we knew what you were actually having trouble implementing.although one might argue it is better to understand the concepts and theories underlying basic programming concepts rather than just trying to copy/paste code of the internet.

Edited by thescientist
Link to comment
Share on other sites

The idea you gave. The reason I came here is to ask for help. If someone could help me get the above script to work with multiple passwords. I'm sure it's simple for those who knows the language. Except I don't have the time to. I'm not here to learn it. I'm sure I could take classes. But like I said I don't have the time. I'm also willing to pay to get it written. Not sure how much I'd get charged but if reasonable I would do it. Thank you for your time.

Edited by intakep
Link to comment
Share on other sites

you mean the array idea? you should easily be able to look up how to use arrays. they're one of the most building blocks of programming. We'll all be more than willing to help, but not do. Take a stab and come back with an attempt.other than that, if you are not willing to invest anytime to learn, it makes all the less motivated to help. give and take.

Edited by thescientist
Link to comment
Share on other sites

It might be that easy, but you have to learn enough to be able to ask a specific question. This kind of online learning is the toughest I've ever encountered. It also produces the greatest capabilities. A person that can script with nothing more than a text editor is guaranteed to have enough for the rest of their life.

Link to comment
Share on other sites

Well you see, I didn't think it was complicated, that's how come I asked. I thought it'd be couple of changing in the code but if not, ok.Thanks for your time.
not a go-getter eh? I see why you don't get why no one is just going to just DO IT FOR YOU seeing as it is as simple as a couple of lines. (especially if you're not even going to try) :) Edited by thescientist
Link to comment
Share on other sites

yet I see no attempts at implementing the suggestions provided....bottom line: we understand that you are just copy/pasting this from the internet and that you might not intuitively understand our suggestions, but humor us and at least try and put the effort forward by showing some sort of attempt at implementing the suggestion provided. You'll probably find you'll be greeted with a much more receptive audience.

Edited by thescientist
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...