Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ex02
- --------------------------------------------------------------------------------------
- modif.php
- --------------------------------------------------------------------
- <?php
- if ($_POST['login'] && $_POST['oldpw'] && $_POST['newpw'] && $_POST['submit'] && ($_POST['submit'] === "OK"))
- {
- $path_f = "../private/passwd";
- $db = unserialize(file_get_contents($path_f));
- if ($db)
- {
- $exista = 0;
- foreach ($db as $key => $value)
- {
- if ($value['login'] === $_POST['login'] && $value['passwd'] === hash("whirlpool", $_POST['oldpw']))
- {
- $exista = 1;
- $db[$key]['passwd'] = hash("whirlpool", $_POST['newpw']);
- }
- if ($exista)
- {
- file_put_contents($path_f, serialize($db));
- echo $_POST['submit'] . "\n";
- }
- else
- echo "ERROR\n";
- }
- }
- else
- {
- echo "ERROR\n";
- }
- }
- else
- {
- echo "ERROR\n";
- }
- ?>
- ------------------------------------------------------------------------
- index.html
- ------------------------------------------------------------------------
- <html>
- <body>
- <form method="post" action="modif.php" name="modif.php">
- Username: <input type="text" name="login" />
- <br/>
- Old password: <input type="text" name="oldpw" />
- <br/>
- New password: <input type="text" name="newpw" />
- <br/>
- <input type="submit" name="submit" value="OK" />
- </form>
- </body>
- </html>
- ---------------------------------------------------------------------------------------------------------------------
- final ex02
- ---------------------------------------------------------------------------------------------------------------------
- ex03
- ---------------------------------------------------------------------------------------------------------------------
- auth.php
- --------------------------------------------------------------------------
- <?php
- function auth($login, $passwd)
- {
- if (!$login || !$passwd)
- return FALSE;
- $db = unserialize(file_get_contents("../private/passwd"));
- if ($db)
- {
- foreach ($db as $key => $value)
- {
- if ($value['login'] === $login && $value['passwd'] === hash('whirlpool', $passwd))
- return TRUE;
- else
- return FALSE;
- }
- }
- else
- return FALSE;
- }
- ?>
- ----------------------------------------------------------------------------
- login.php
- ----------------------------------------------------------------------------
- <?php
- require_once("auth.php");
- session_start();
- if ($_GET['login'] && $_GET['passwd'] && auth($_GET['login'], $_GET['passwd']))
- {
- $_SESSION['loggued_on_user'] = $_GET['login'];
- echo "OK\n";
- }
- else
- {
- $_SESSION['loggued_on_user'] = "";
- echo "ERROR\n";
- }
- ?>
- ------------------------------------------------------------------------------
- logout.php
- ------------------------------------------------------------------------------
- <?php
- session_start();
- $_SESSION['loggued_on_user'] = "";
- ?>
- ------------------------------------------------------------------------------
- whoami.php
- ------------------------------------------------------------------------------
- <?php
- session_start();
- if ($_SESSION['loggued_on_user'])
- {
- echo $_SESSION['loggued_on_user'] . "\n";
- }
- else
- echo "ERROR\n";
- ?>
- ---------------------------------------------------------------------------------------------------------------------
- final ex03
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement