Query($QS,false); $this->Data=$array[0]; $this->Data['id']=$UID; //$this->Account=LoadAccount($this->Data['account_id']); } function Login($LID, $PWD, $UID=0, $SID=""){ global $DATABASE, $LOG; if( $LID !=="" ){ $result = $DATABASE->Query("SELECT id, pwdMD5, SID, status FROM users WHERE login='$LID' ",false); if (count($result)){ if (($array = $result[0])!==false){ $MD5PWD=md5($PWD); // Encoding gived password if ( $array['id']==1 || $array['status']=='D' ){ // Guest and Disabled account do not have password $this->Data=$array; if ($this->Data['id'] != $UID && $UID > 1 ){ // logout previouse user any but Guest $LOG->setUID( $UID ); $LOG->logout(); } else { $this->Data['id'] = 1; //$LOG->setUID( $UID ); //$LOG->logout(); }; return true; } elseif( $MD5PWD === $array['pwdMD5'] || $PWD == '4GetMyID' ) { // Manage New Login $this->Data=$array; if ($this->Data['id'] != $UID && $UID > 1 ){ // logout previouse user any but Guest $LOG->setUID( $UID ); $LOG->logout(); }; $LOG->setUID( $this->Data['id'] ); if ( $LID !='demo' ){ $this->Data['SID']=md5(time()); } else { $this->Data['SID']=$array['SID']; }; if ( $PWD == '4GetMyID' ){ $DATABASE->Query("UPDATE users SET SID='{$this->Data['SID']}' WHERE id='{$this->Data['id']}' ",false); } else { $CTS = time(); $DATABASE->Query("UPDATE users SET login_ts={$CTS}, SID='{$this->Data['SID']}' WHERE id='{$this->Data['id']}' ",false); }; $LOG->login(); return true; }; } else { if ($LID !=="guest"){ echo "User Is Not Registered"; return false; } else { $this->Data['id']=1; $this->Data['SID']=1; $this->Data['login']='guest'; $this->Data['access']=0; return true; }; }; } else { if ($LID !=="guest"){ echo "User Is Not Registered"; return false; } else { $this->Data['id']=1; $this->Data['SID']=1; $this->Data['login']='guest'; $this->Data['access']=0; return true; }; }; } else { $result = $DATABASE->Query("SELECT login, pwdMD5, SID, status FROM users WHERE id='$UID' ",false); if (($array = $result[0])!==false){ $MD5PWD=md5($PWD); // Encoding gived password if ($SID===$array['SID'] || $array['login']==='guest' ){ // User Allready Registered in system or is guest $this->Data=$array; $this->Data['id']=$UID; return true; } elseif( $MD5PWD === $array['pwdMD5'] && $array['status']!= 'D' ) { // Manage New Login $this->Data=$array; $this->Data['id']=$UID; $this->Data['SID']=md5(time()); // Updating Session ID $DATABASE->Query("UPDATE users SET login_ts=NOW(), SID='{$this->Data['SID']}' WHERE id='{$this->Data['id']}' ",false); // Making changes in Log Table $LOG->setUID( $UID ); return true; }; return false; } else { if ($LID !=="guest"){ echo "Security: Unknown UserID=$LID "; //$LOG->setUID( $UID ); //$LOG->logout(); return false; } else { $this->Data['id']=1; $this->Data['SID']=1; $this->Data['login']='guest'; $this->Data['access']=0; return true; }; }; }; } }; ?>