Guest User

Untitled

a guest
Jul 6th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.88 KB | None | 0 0
  1. <?php
  2. class Login
  3. {
  4.     public static function HandleLogin()
  5.     {
  6.         if(isset($_POST['username'], $_POST['password']))
  7.         {
  8.             global $Session;
  9.             global $User;
  10.             global $error;
  11.            
  12.            
  13.            
  14.             $username = $_POST['username'];  // We don't need to clean the data because it's all auto-cleaned by the database class
  15.             $password = hash_string($_POST['password']);
  16.            
  17.             $process = $User->getData('password', $username);
  18.             if($process == $password)
  19.             {
  20.                 $check = $User->CheckBan($username);
  21.                 if($check)
  22.                 {
  23.                     $error = 'banned';
  24.                     return;
  25.                 }
  26.                 else
  27.                 {
  28.                     // Set the user's last IP address
  29.                     $process = $User->WriteData('ip_last', USER_IP, $username);
  30.                    
  31.                     // Register the session & log it.
  32.                     $Session->Set('username', $username);
  33.                    
  34.                     // Redirect the user to the "me" page.
  35.                     redirect('me.php');
  36.                 }
  37.             }
  38.             else
  39.             {
  40.                 $error = 'credentials';
  41.                 return;
  42.             }
  43.         }
  44.     }
  45.     public static function ErrorHandler()
  46.     {
  47.         global $error;
  48.        
  49.         if(isset($error))
  50.         {
  51.             echo '<div id="error">';
  52.            
  53.             switch($error)
  54.             {
  55.                 case "credentials":
  56.                     echo '<b>Error:</b> Incorrect Login Credentials';
  57.                 break;
  58.            
  59.                 case "banned":
  60.                     echo 'Your account has been banned.';
  61.                 break;
  62.             }
  63.             echo '</div>';
  64.         }
  65.     }
  66. }
Add Comment
Please, Sign In to add comment