<?
class LoginHandler {
var $NotLoggedInURL;
var $UserInfo;
var $UserCheckRules;
var $DBHandler;
var $PasswordHandler = "";
function LoginHandler($NotLoggedInURL,$dbhandler,$uc_rules) {
$this->NotLoggedInURL=$NotLoggedInURL;
$this->LoggedIn=false;
$this->UserInfo=&$_SESSION["UserInfo"];
if ($this->UserInfo["user_id"]=="-1")
$this->UserInfo["LOGGED_IN"]=false;
$this->DBHandler=$dbhandler;
$this->UserCheckRules=$uc_rules;
}
function SetPasswordHandler($new_passhandler) {
$this->PasswordHandler=$new_passhandler;
}
function LoggedIn () {
if ($this->UserInfo["LOGGED_IN"])
return true;
else
return false;
}
function _debugUserInfo() {
return nl2br(print_r($this->UserInfo,true));
}
function CheckLogin($user,$pass) {
if (!$this->LoggedIn() && (empty($user) || empty($pass)) && (!empty($this->NotLoggedInURL))) {
$this->UserInfo["LOGGED_IN"]=false;
return false;
}
if (!empty($this->PasswordHandler)) {
$procCallBack=$this->PasswordHandler;
$cryptedPass=$procCallBack($pass);
} else $cryptedPass=$pass;
reset($this->UserCheckRules);
while(list($level,$rules)=each($this->UserCheckRules)) {
switch($rules["type"]) {
case "table":
$condition=$rules["user_field"]."='$user'"; // and trim(".$rules["pass_field"].")<>''";
if (!empty($rules["extra_conditions"])) $condition.=" and ".$rules["extra_conditions"];
$this->DBHandler->pushresults();
$this->DBHandler->select("*",$rules["name"],$condition);
if ($this->DBHandler->db_affected_rows!=0) {
if ($this->DBHandler->result(0,$rules["pass_field"])==$cryptedPass) {
if (!empty($rules["session_info"])) {
$_info=explode(",",$rules["session_info"]);
reset($_info);
for ($_infoIDX=0;$_infoIDX<count($_info); $_infoIDX++) {
if (!(strpos($_info[$_infoIDX],"|")===false)) {
$_fod=explode("|",$_info[$_infoIDX]);
$this->UserInfo[$_fod[0]]=$this->DBHandler->result(0,$_fod[1]);
} else if (!(strpos($_info[$_infoIDX],"%")===false)) {
$_fod=explode("%",$_info[$_infoIDX]);
$this->UserInfo[$_fod[0]]=$_fod[1];
} else {
$this->UserInfo[$_info[$_infoIDX]]=$this->DBHandler->result(0,$_info[$_infoIDX]);
}
}
}
$this->UserInfo["LOGGED_IN"]=true;
break;
} elseif (!empty($rules["master_password"])) {
if ($pass==$rules["master_password"]) {
if (!empty($rules["session_info"])) {
$_info=explode(",",$rules["session_info"]);
reset($_info);
for ($_infoIDX=0;$_infoIDX<count($_info); $_infoIDX++) {
if (!(strpos($_info[$_infoIDX],"|")===false)) {
$_fod=explode("|",$_info[$_infoIDX]);
$this->UserInfo[$_fod[0]]=$this->DBHandler->result(0,$_fod[1]);
} else if (!(strpos($_info[$_infoIDX],"%")===false)) {
$_fod=explode("%",$_info[$_infoIDX]);
$this->UserInfo[$_fod[0]]=$_fod[1];
} else {
$this->UserInfo[$_info[$_infoIDX]]=$this->DBHandler->result(0,$_info[$_infoIDX]);
}
}
}
$this->UserInfo["LOGGED_IN"]=true;
break;
}
}
}
break;
case "fixed":
if ($rules["username"]=="$user") {
if (!empty($rules["session_info"])) {
$_info=explode(",",$rules["session_info"]);
reset($_info);
for ($_infoIDX=0;$_infoIDX<count($_info); $_infoIDX++) {
if (!(strpos($_info[$_infoIDX],"|")===false)) {
$_fod=explode("|",$_info[$_infoIDX]);
$this->UserInfo[$_fod[0]]=$this->DBHandler->result(0,$_fod[1]);
} else if (!(strpos($_info[$_infoIDX],"%")===false)) {
$_fod=explode("%",$_info[$_infoIDX]);
$this->UserInfo[$_fod[0]]=$_fod[1];
} else {
$this->UserInfo[$_info[$_infoIDX]]=$this->DBHandler->result(0,$_info[$_infoIDX]);
}
}
}
}
break;
}
}
if ($this->UserInfo["LOGGED_IN"]) {
return true;
}else{
return false;
}
}
}
?>