Guest User

Untitled

a guest
Jun 7th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.43 KB | None | 0 0
  1. ************************* config.php *********************************
  2. $config['DB_NAME_FORUM']        =   "cpg_db";
  3. $config['DB_USER_TABLE']        =   "wcf1_user";
  4. $config['DB_RANK_TABLE']        =   "wcf1_user_rank";
  5. $config['ADMIN_RANK']   =   array("Admin","Headadmin","Super Moderator");
  6. $config['MOD_RANK']     =   array("Moderator");
  7.  
  8. ************************* user.php ***********************************
  9. class User {
  10.     public $userID;
  11.     public $name;
  12.     public $password;
  13.     public $hash;
  14.     public $valid;
  15.     public $admin; 
  16.    
  17.     public function User(){
  18.         $this->valid = false;  
  19.     }
  20.    
  21.     public function login($user, $pass){
  22.         global $db, $config;
  23.         $result = $db->query_first("SELECT userID, username, password, salt FROM ".$config['DB_NAME_FORUM'].".".$config['DB_USER_TABLE']." WHERE username = '".$db->escape($user)."' AND banned = 0");
  24.         if(empty($result['username'])){
  25.             $this->valid = false;
  26.             return $this->valid;
  27.         }
  28.         $hash = $this->getHash($pass,$result['salt']);
  29.         if($hash == $result['password']){
  30.             $this->userID = $result['userID'];
  31.             $this->name = $result['username'];
  32.             $this->password = $pass;
  33.             $this->hash = $result['password'];
  34.             $this->valid = true;
  35.             $rank_query = $db->query_first("SELECT r.rankTitle as rank
  36.                                             FROM ".$config['DB_NAME_FORUM'].".".$config['DB_USER_TABLE']." u, ".$config['DB_NAME_FORUM'].".".$config['DB_RANK_TABLE']." r
  37.                                             WHERE u.username = '".$db->escape($user)."' AND u.rankID = r.rankID");
  38.             $this->admin = (array_search($rank_query['rank'], $config['MOD_RANK'])>-1) ? 1 : 0;
  39.             $this->admin = (array_search($rank_query['rank'], $config['ADMIN_RANK'])>-1) ? 2 : $this->admin;                                   
  40.         }else{
  41.             $this->valid = false;
  42.         }
  43.         return $this->valid;
  44.        
  45.     }
  46.    
  47.     private function getHash($password, $salt){
  48.         return sha1($salt.sha1($salt.sha1($password)));
  49.     }
  50.    
  51.     public function loadSession(){
  52.         if(empty($_SESSION['login_username']) || empty($_SESSION['login_password'])){
  53.             return false;
  54.         }
  55.         return $this->login($_SESSION['login_username'],$_SESSION['login_password']);
  56.     }
  57.    
  58.     public function saveSession(){
  59.         if($this->valid === true){
  60.             $_SESSION['login_username'] = $this->name;
  61.             $_SESSION['login_password'] = $this->password;
  62.         }
  63.     }
  64.    
  65.     public function logout(){
  66.         unset($_SESSION['login_username']);
  67.         unset($_SESSION['login_password']);
  68.         $this->valid=false;
  69.         $this->admin=0;
  70.         $this->name = null;
  71.         $this->password = null;
  72.         $this->hash = null;
  73.         $this->userID = null;
  74.     }
  75. }
Add Comment
Please, Sign In to add comment