Advertisement
Guest User

Untitled

a guest
Jun 4th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.33 KB | None | 0 0
  1.     public function checkLogin($secret_key) {
  2.         global $db;
  3.        
  4.         if (isset($_COOKIE['HORBLECOOKIE'])) :
  5.             $data = explode('-', $_COOKIE['HORBLECOOKIE']);
  6.             $_SESSION['uid'] = $data[1];
  7.             $_SESSION['hash'] = $data[0];
  8.         endif;
  9.        
  10.         $this->uid = $_SESSION['uid'];
  11.         $this->hashkey = $_SESSION['hash'];
  12.        
  13.         if (!isset($this->uid) || !isset($this->hashkey)) {
  14.             $this->logout();
  15.         } else {
  16.             $check = sha1($this->uid . $this->ip . $secret_key);
  17.             if ($check != $this->hashkey) {
  18.                 $this->logout();
  19.             } else {
  20.                 $query = $db->execute("SELECT * FROM users WHERE id='".$this->uid."'") or die(mysql_error());
  21.                 $userarray = $db->fetchassoc($query);
  22.                 if ($db->numrows($query) == 0) {
  23.                     $this->logout();
  24.                 }
  25.                 foreach($userarray as $key=>$value) {
  26.                     $user->$key = $value;
  27.                 }
  28.                 $this->logged_in = 1;
  29.                 return $user;
  30.             }
  31.         }
  32.     }
  33.  
  34.     public function login($email, $password, $keepmein, $secret_key) {
  35.         global $msgError;
  36.        
  37.         $this->email = clean($email, 1, 1, 3);
  38.         $this->password = clean($password, 1 , 1, 0);
  39.        
  40.         if (empty($this->email) || empty($this->password)) {
  41.            
  42.             $msgError = "You have left empty fields!";
  43.            
  44.             return;
  45.            
  46.         }
  47.        
  48.         $result = User::confirmUserPass($this->email, $this->password);
  49.        
  50.         if ($result == 1 || $result == 3) {
  51.            
  52.             $msgError = "Please enter valid email and password.";
  53.            
  54.             return;
  55.            
  56.         } elseif ($result == 2) {
  57.            
  58.             $msgError = "Your user account has not been activated yet!";
  59.            
  60.             return;
  61.            
  62.         }
  63.        
  64.         if (empty($msgError)) {
  65.            
  66.             $this->userinfo = User::getUserInfo('users', 'email', $this->email);
  67.            
  68.             $this->id = $_SESSION['uid'] = $this->userinfo['id'];
  69.             $this->hashkey = $_SESSION['hash'] = sha1($this->id . $this->ip . $secret_key);
  70.              
  71.             User::updateUserField('users', 'email', $this->email, "last_login", $this->time);
  72.             User::updateUserField('users', 'email', $this->email, "ip", $this->ip);
  73.             User::updateUserField('users', 'email', $this->email, "times_logged", $this->userinfo['times_logged'] + 1);
  74.            
  75.             if ($keepmein) {
  76.                
  77.                 setcookie("HORBLECOOKIE", $this->hashkey . '-' . $this->id, $this->time + COOKIE_EXPIRE);
  78.                
  79.             }
  80.            
  81.             $this->logged_in = 1;
  82.  
  83.             return true;
  84.            
  85.         } else {
  86.            
  87.             return false;
  88.            
  89.         }
  90.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement