Guest User

Untitled

a guest
May 18th, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  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 = ""
  22. $result = mysql_query($sql) or die("Query failed: " . $sql);
  23. $row = mysql_fetch_array($result);
  24.  
  25. if($this->IsValid)
  26. {
  27. $this->SetPermissions($row)
  28. }
  29.  
  30. mysql_free_result($result);
  31. unset($sql, $result, $row);
  32.  
  33. return $this->IsValid();
  34. }
  35.  
  36. public function LoadByID($id)
  37. {
  38. $sql = ""
  39. $result = mysql_query($sql) or die("Query failed: " . $sql);
  40. $row = mysql_fetch_array($result);
  41.  
  42. if($this->IsValid)
  43. {
  44. $this->SetPermissions($row)
  45. }
  46.  
  47. mysql_free_result($result);
  48. unset($sql, $result, $row);
  49.  
  50. return $this->IsValid();
  51. }
  52.  
  53. public function SetPermissions($row)
  54. {
  55. // evaluate row array and set permission properties here
  56. }
  57. }
  58.  
  59. class Admin
  60. {
  61. private $user;
  62. private $authenticated;
  63.  
  64. public __construct()
  65. {
  66. $user = new User();
  67. $authenticated = "";
  68. }
  69.  
  70. public function IsAuthenticated()
  71. {
  72. if($this->authenticated == "") $this->Authenticate();
  73. return $this->authenticated;
  74. }
  75.  
  76. public function Authenticate()
  77. {
  78. if(isset($_SESSION['userid']))
  79. $this->authenticated = // unhash md5 and pass to $this->user->LoadByID();
  80. elseif(isset($_POST['username'], $_POST['password'])
  81. {
  82. $this->authenticated = $this->user->LoadByLogin($_POST['username'], $_POST['password']);
  83. if($this->authenticated) $_SESSION['userid'] = md5($user->id);
  84. }
  85. else
  86. $this->authenticated = false;
  87. }
  88. }
  89.  
  90. $admin = new Admin();
  91. if($admin->IsAuthenticated())
  92. {
  93. Header("Login: admin.php");
  94. }
  95. else
  96. {
  97. // Login form
  98. }
Add Comment
Please, Sign In to add comment