daily pastebin goal
44%
SHARE
TWEET

Untitled

a guest Mar 17th, 2018 170 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class User
  2. {
  3.     private $username;
  4.     private $password;
  5.     private $id;
  6.    
  7.     public __construct() {
  8.         $this->username = "";
  9.         $this->password = "";
  10.         $this->id = 0;
  11.     }
  12.    
  13.     public function IsValid()
  14.     {
  15.         if($id != 0) return true;
  16.         else return false;
  17.     }
  18.    
  19.     public function LoadByLogin($username, $password)
  20.     {
  21.         // $sql, populate id if valid
  22.         return $this->IsValid();
  23.     }
  24.    
  25.     public function LoadByID($id)
  26.     {
  27.         // unMD5 $id, $sql, then set id if valid
  28.         return $this->IsValid();
  29.     }
  30. }
  31.  
  32. class Admin
  33. {
  34.     private $user;
  35.     private $authenticated;
  36.    
  37.     public __construct()
  38.     {
  39.         $user = new User();
  40.         $authenticated = "";
  41.     }
  42.    
  43.     public function IsAuthenticated()
  44.     {
  45.         if($this->authenticated == "") $this->Authenticate();
  46.         return $this->authenticated;
  47.     }
  48.    
  49.     public function Authenticate()
  50.     {
  51.         if(isset($_SESSION['userid']))
  52.             $this->authenticated =  // unhash md5 and pass to $this->user->LoadByID();
  53.         elseif(isset($_POST['username'], $_POST['password'])
  54.         {
  55.             $this->authenticated =  $this->user->LoadByLogin($_POST['username'], $_POST['password']);
  56.             if($this->authenticated) $_SESSION['userid'] = md5($user->id);
  57.         }  
  58.         else
  59.             $this->authenticated =  false;
  60.     }
  61. }
  62.  
  63. $admin = new Admin();
  64. if($admin->IsAuthenticated())
  65. {
  66.     Header("Login: admin.php");
  67. }
  68. else
  69. {
  70.     // Login form
  71. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top