Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.67 KB | None | 0 0
  1. <?
  2. $user = "packz";
  3. //password="password"
  4. $pass = "5f4dcc3b5aa765d61d8327deb882cf99";
  5.  
  6. /* questo va prima di ogni contenuto */
  7. session_start();
  8.  
  9. /*
  10.  * Se l'utente non è loggato oppure non si è in una chiamata POST
  11.  * corretta, visualizza il form per effettuare il login.
  12.  */
  13. $doYouWantToLogout=!empty($_GET["logout"]);
  14. $isLogged=!empty($_SESSION["is_logged"]);
  15. $isCorrectPOST=isset($_POST["user"]) && isset($_POST["password"]);
  16. $isNeededForm=!$isLogged && !$isCorrectPOST;
  17.  
  18. function areRightCredentials($user, $password) {
  19.     return ($user == $_POST["user"]) &&
  20.         ($password == md5($_POST["password"]));
  21. }
  22.  
  23. function redirectToHimself() {
  24.     header("Location: test-login.php");
  25. }
  26.  
  27. if ($doYouWantToLogout) {
  28.     $_SESSION = array();
  29.     session_destroy();
  30.     redirectToHimself();
  31. }
  32.  
  33. function printForm() {
  34. ?>
  35.     <form method="POST" action="test-login.php">
  36.         <b>username:</b><input type="text" name="user"/>
  37.         <b>password:</b><input type="text" name="password" />
  38.         <input type="submit"/>
  39.     </form>
  40. <?
  41. }
  42.  
  43. if ($isNeededForm) {
  44.     printForm();
  45. } else {
  46.     if ($isLogged) {
  47.         $_SESSION["visites"]++;
  48. ?>
  49. <p>you are fucking inside for the <? echo $_SESSION["visites"];?>th times</p>
  50. <p>Do you want to <a href="?logout=miao">logout</a>?</p>
  51. <?
  52.     } elseif ($isCorrectPOST) {
  53.         if(areRightCredentials($user, $pass)) {
  54.             /*
  55.              * SECURITY FLAW:
  56.              * se non ci metti session_regenerate_id() sul server
  57.              * viene usato lo stesso PHPSESSID anche dopo aver
  58.              * effettuato il logout.
  59.              */
  60.             session_regenerate_id();
  61.             $_SESSION["user"] = $user;
  62.             $_SESSION["visites"] = 0;
  63.             $_SESSION["is_logged"] = 1;
  64.             redirectToHimself();
  65.         } else
  66.             printForm();
  67.     }
  68. }
  69. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement