Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- /**
- * General login testing script.
- *
- * @author Packz Enoch
- */
- $user = "packz";
- //password="password"
- $pass = "5f4dcc3b5aa765d61d8327deb882cf99";
- /* questo va prima di ogni contenuto */
- session_start();
- /**
- * Variabili globali contenenti info utili sul comportamento da seguire:
- * se l'utente non รจ loggato oppure non si รจ in una chiamata POST
- * corretta, visualizza il form per effettuare il login.
- *
- * @global boolean $doYouWantToLogout
- * @name $doYouWantToLogout
- */
- $doYouWantToLogout=!empty($_GET["logout"]);
- /**
- * @global boolean $isLogged
- * @name $isLogged
- */
- $isLogged=!empty($_SESSION["is_logged"]);
- $isCorrectPOST=isset($_POST["user"]) && isset($_POST["password"]);
- $isNeededForm=!$isLogged && !$isCorrectPOST;
- /**
- * Controlla che le credenziali siano corrette.
- *
- * @param string $user nome utente
- * @param string $password credenziale di accesso MD5-hashed
- * @return boolean
- */
- function areRightCredentials($user, $password) {
- return ($user == $_POST["user"]) &&
- ($password == md5($_POST["password"]));
- }
- function redirectToHimself() {
- header("Location: test-login.php");
- }
- if ($doYouWantToLogout) {
- $_SESSION = array();
- session_destroy();
- redirectToHimself();
- }
- function printForm() {
- ?>
- <form method="POST" action="test-login.php">
- <b>username:</b><input type="text" name="user"/>
- <b>password:</b><input type="text" name="password" />
- <input type="submit"/>
- </form>
- array_
- <?
- }
- if ($isNeededForm) {
- printForm();
- } else {
- if ($isLogged) {
- $_SESSION["visites"]++;
- ?>
- <p>you are fucking inside for the <? echo $_SESSION["visites"];?>th times</p>
- <p>Do you want to <a href="?logout=miao">logout</a>?</p>
- <?
- } elseif ($isCorrectPOST) {
- if(areRightCredentials($user, $pass)) {
- /*
- * SECURITY FLAW:
- * se non ci metti session_regenerate_id() sul server
- * viene usato lo stesso PHPSESSID anche dopo aver
- * effettuato il logout.
- */
- session_regenerate_id();
- $_SESSION["user"] = $user;
- $_SESSION["visites"] = 0;
- $_SESSION["is_logged"] = 1;
- redirectToHimself();
- } else
- printForm();
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement