Location: PHPKode > projects > MyOWNSpace > MyOWNspace_v8.2/www/classes/quickauth.php
<?
/*
***************************************************************************
Script name: Obie Quick Authentication script (one user version)
Version: 1.0
Date: 12 March 2003
Author: Minh Nguyen Duong - http://obiewebsite.sourceforge.net

This Software is FREE and can be modified 
and redistributed under the condition that 
the copyright and information above stays 
intact and with the script.

If you redistribute any Obie's script, please link back 
to http://obiewebsite.sourceforge.net

For more information about GNU(GPL), please visit http://www.GNU.org

USAGE:*********************************************************************
Paste code below all pages that require authentication

==========start=code=======>
	include "PATH_TO/quickauth.php"; //in VERY TOP OF THE HEAD OF your PHP pages
		//Other code
	if( checkauth() ) { 
		//If not authorize, it returns value FALSE and NOT print the login box
	}
	if( checklogin() ) { 
		//If not authorize, it prints the login box and returns FALSE
	}

	authcontrolbar(); //Your control bar for logging out, changing new password. Can be placed anywhere in a pages.
<========end=code===========

------------------------------------------------
Control Panel has logging out and encryted account generator function.
You can enter the CP manually:

-Control Panel (Logging out and Changing new account function) : quickauth.php?auth=quickauthcp
 or you can add the Control Bar to anywhere in a page as the function: authcontrolbar();
-Loging out: quickauth.php?auth=logout
-New username/password generator: quickauth.php?auth=generateform

------------------------------------------------
Default account (if you forget your password):
$my_username="admin";
$my_password="c3284d0f94606de1fd2af172aba15bf3";

***************************************************************************
*/

//*********************CONFIGURATIONS**************************************

//$my_username="admin"; //Your username

//$my_password="c3284d0f94606de1fd2af172aba15bf3"; //Your ecrypted password (generator in Control Panel)

$cookiename="myownspace";

$lifetime=1;

/*
**********************ENCRYPTING EMPRESSION*******************************
***You can build your own Empression by using md5() or crypt() function***
**************************************************************************
*/

function encr($s){
	$s=md5(md5($s)); //The crypting empression here
	return $s;
}
include "myownusers.php";

//**************************PLEASE DO NOT CHANGE BELOW********************

if ($_POST['auth']=='login'){
  $user=$_POST['user'];
	$pass=encr($_POST['pass']);
	$checkauth=FALSE;
	$cookielifetime=time() + $lifetime*3600;
	$rawuser=$user;
	$rawpass=$pass;
	$cookievalue="$rawuser|$rawpass|";
for ($i=1;$i<=count($myown_user);$i++){
$my_username=$myown_user[$i]['login'];
$my_password=$myown_user[$i]['pass'];
if($user==$my_username && $pass==$my_password) { $checkauth=TRUE; break; }
}
	if($checkauth==FALSE) errormessage("Your username or password is not correct");
	else {
		setcookie($cookiename,$cookievalue,$cookielifetime);
		//$url = $_SERVER['REQUEST_URI'] ."?" .$refurl;
		$url="test.php";
		header("Location: $url");
	}
}

if ($_GET['auth']=='logout'){
	setcookie($cookiename,"",time()-$lifetime*3600);
	$refurl=str_replace("^","&",$refurl);
	$refurl=str_replace("~","=",$refurl);
	$url = $_SERVER['REQUEST_URI'] ."?" .$refurl;
	header("Location: $url");
}


$ma=explode("|",$_COOKIE[$cookiename]);
$rawuser=$ma[0];$rawpass=$ma[1];

function loginbox(){
global $QUERY_STRING;
	print("
	<style>
		.obietext {font-family: Arial; font-size: 11pt; font-weight: normal;}
	</style>
	<div align=center class=obietext>
	You have not loged in yet<br><br>
	<table border=0 cellspacing=1 cellpadding=4 bgcolor=#AED0F2>
	<tr><td bgcolor=white>
	<form method=POST action=quickauth.php>
	<input type=hidden name=auth value=login>
	<input type=hidden name=refurl value=".$QUERY_STRING.">
	<table width=100% border=0 cellspacing=1 cellpadding=4 class=obietext>
	<tr><td width=99% bgcolor=#F0F0F0>Username</td><td width=1% bgcolor=#F0F0F0><input type=text size=10 name=user></td></tr>
	<tr><td width=99% bgcolor=#F0F0F0>Password</td><td width=1% bgcolor=#F0F0F0><input type=password size=10 name=pass></td></tr>
	</table>
	<input type=submit value=\"Login\"> *<font size=1>Require COOKIE enabled</font>
	</td></tr>
	</form></table></div>
	<p align=right class=obietext>Authentication Script by <a href=http://obiewebsite.sourceforge.net target=_blank>Quick AUTH</a></p>");
}
function errormessage($mess){
	print("<p align=center><font color=red>$mess</font></p>");
}
function loged($u){
global $QUERY_STRING;
	$refurl=str_replace("&","^",$_SERVER["QUERY_STRING"]);
	$refurl=str_replace("=","~",$refurl);
	print("<div align=left style=\"border: solid 1 gray;\">Loged as <b>".$u."</b><br> 
	+ <a href=".$_SERVER['REQUEST_URI']."?auth=logout&refurl=".$refurl.">Logout</a><br>
	+ <a href=".$_SERVER['REQUEST_URI']."?auth=generateform>Change password</a></div>");
}

//**************************MAIN FUNCTIONS*******************************************************

function checkauth(){

$checklogin=FALSE;
global $rawuser;
global $rawpass;
include "myownusers.php";
echo $rawuser."#".$rawpass;
for ($i=1;$i<=count($myown_user);$i++){
$my_username=$myown_user[$i]['login'];echo "33:".$my_username;
$my_password=$myown_user[$i]['pass'];
if($my_username==$rawuser && $my_password==$rawpass && rawuser!="" && rawpass!="") 
{$checklogin=TRUE;break;}
}
return $checklogin;
}

function checklogin(){
	if(!checkauth()) {
		loginbox();
		return FALSE;
	}
	else return TRUE;
}

function authcontrolbar(){
global $rawuser;
	if(checkauth()) loged($rawuser);
}

//************************END*******************************************************************

if ($_POST['auth']=='generateform'){
	print("<font face=Arial>
	<form method=POST action=".$_SERVER['REQUEST_URI'].">
	<input type=hidden name=auth value=generate>
	<h3><i>Quick AUTH: Generate new Username/Password</i></h3>
	New Username <input type=text name=newuser size=10> 
	New Password <input type=text name=newpass size=10>
	<input type=submit value=\"Generate\">
	</form>
	<hr size=1 color=black>
	");
}

if ($_POST['auth']=='generate'){
	if(checkauth()){
	$newpass=encr($newpass);
	print("<font face=Arial>
	<h3><i>Quick AUTH: Generated successfully</i></h3>
	Open <u>quickauth.php</u> file (as any Text-editor like Notepad....) and copy the <b>bolded</b>
	 text and replace to your variable that in the CONFIGURATIONS area of the file, 
	then <u>save</u> the file and <u>upload</u> to your server:
	<p><font color=brown>
	\$my_username=\"<b>$newuser</b>\";
	<br><br>\$my_password=\"<b>$newpass</b>\";
	</font></p>
	<hr size=1 color=black>");
	}
	else print("<p align=center>ERROR: You must log in before using this function</p>");
}
if ($_POST['auth']=='quickauthcp'){
	if(checkauth()) {
		print("<h3><i>Quick AUTH self Control Panel</i></h3>");
		loged($rawuser);
		print("<p align=center>Welcome to Obie Quick AUTH 1.0 control panel
		<br><br>Powered by <a href=http://obiewebsite.sourceforge.net target=_blank>obiewebsite.sourceforge.net</a> (C)(R)</p>");
	}
}
?>
Return current item: MyOWNSpace