Advertisement
Guest User

Untitled

a guest
Jul 1st, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.13 KB | None | 0 0
  1. <?
  2.     /**
  3.      * General login testing script.
  4.      *
  5.      * @author Packz Enoch
  6.      */
  7. $user = "packz";
  8. //password="password"
  9. $pass = "5f4dcc3b5aa765d61d8327deb882cf99";
  10.  
  11. /* questo va prima di ogni contenuto */
  12. session_start();
  13.  
  14. /**
  15.  * Variabili globali contenenti info utili sul comportamento da seguire:
  16.  * se l'utente non รจ loggato oppure non si รจ in una chiamata POST
  17.  * corretta, visualizza il form per effettuare il login.
  18.  *
  19.  * @global boolean $doYouWantToLogout
  20.  * @name $doYouWantToLogout
  21.  */
  22. $doYouWantToLogout=!empty($_GET["logout"]);
  23. /**
  24.  * @global boolean $isLogged
  25.  * @name $isLogged
  26.  */
  27. $isLogged=!empty($_SESSION["is_logged"]);
  28. $isCorrectPOST=isset($_POST["user"]) && isset($_POST["password"]);
  29. $isNeededForm=!$isLogged && !$isCorrectPOST;
  30.  
  31. /**
  32.  * Controlla che le credenziali siano corrette.
  33.  *
  34.  * @param string $user nome utente
  35.  * @param string $password credenziale di accesso MD5-hashed
  36.  * @return boolean
  37.  */
  38. function areRightCredentials($user, $password) {
  39.     return ($user == $_POST["user"]) &&
  40.         ($password == md5($_POST["password"]));
  41. }
  42.  
  43. function redirectToHimself() {
  44.     header("Location: test-login.php");
  45. }
  46.  
  47. if ($doYouWantToLogout) {
  48.     $_SESSION = array();
  49.     session_destroy();
  50.     redirectToHimself();
  51. }
  52.  
  53. function printForm() {
  54. ?>
  55.     <form method="POST" action="test-login.php">
  56.         <b>username:</b><input type="text" name="user"/>
  57.         <b>password:</b><input type="text" name="password" />
  58.         <input type="submit"/>
  59.     </form>
  60.     array_
  61. <?
  62. }
  63.  
  64. if ($isNeededForm) {
  65.     printForm();
  66. } else {
  67.     if ($isLogged) {
  68.         $_SESSION["visites"]++;
  69. ?>
  70. <p>you are fucking inside for the <? echo $_SESSION["visites"];?>th times</p>
  71. <p>Do you want to <a href="?logout=miao">logout</a>?</p>
  72. <?
  73.     } elseif ($isCorrectPOST) {
  74.         if(areRightCredentials($user, $pass)) {
  75.             /*
  76.              * SECURITY FLAW:
  77.              * se non ci metti session_regenerate_id() sul server
  78.              * viene usato lo stesso PHPSESSID anche dopo aver
  79.              * effettuato il logout.
  80.              */
  81.             session_regenerate_id();
  82.             $_SESSION["user"] = $user;
  83.             $_SESSION["visites"] = 0;
  84.             $_SESSION["is_logged"] = 1;
  85.             redirectToHimself();
  86.         } else
  87.             printForm();
  88.     }
  89. }
  90. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement