Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- auth.php
- <?php
- function auth($login, $passwd)
- {
- $path = "../private/passwd";
- $hash = hash("whirlpool", $passwd);
- $accounts = file_get_contents($path);
- $accounts = unserialize($accounts);
- foreach ($accounts as $elem)
- {
- if ($elem["login"] == $login && $elem["passwd"] == $hash)
- return true;
- }
- return false;
- }
- ?>
- login.php
- <?php
- include("auth.php");
- $login = $_GET['login'];
- $passwd = $_GET['passwd'];
- session_start();
- if (auth($login, $passwd))
- {
- $_SESSION['loggued_on_user'] = $login;
- echo "OK\n";
- }
- else
- {
- $_SESSION['loggued_on_user'] = "";
- echo "ERROR\n";
- }
- ?>
- logout.php
- <?php
- session_start();
- $_SESSION['loggued_on_user'] = "";
- ?>
- <?php
- session_start();
- if ($_SESSION['loggued_on_user'])
- echo $_SESSION['loggued_on_user']."\n";
- else
- echo "ERROR\n";
- ?>
- ////////////////////////////////////////////////////////////////
- auth.php
- <?php
- function auth($login, $passwd)
- {
- $path = "../private/passwd";
- $hash = hash("whirlpool", $passwd);
- $accounts = file_get_contents($path);
- $accounts = unserialize($accounts);
- foreach ($accounts as $elem)
- {
- if ($elem["login"] == $login && $elem["passwd"] == $hash)
- return true;
- }
- return false;
- }
- ?>
- chat.php
- <?php
- session_start();
- if ($_SESSION['loggued_on_user'])
- {
- $folder = "../private";
- $path = "../private/chat";
- $fp = fopen($path, "r");
- flock($fp, LOCK_SH);
- $messages = file_get_contents($path);
- fclose($fp);
- $messages = unserialize($messages);
- foreach ($messages as $key=>$msg)
- echo $msg['time']." <b>".$msg['login']."</b>: ".$msg['msg']."<br />\n";
- }
- else
- echo "ERROR\n";
- ?>
- <head>
- <script>scroll = setTimeout(function(){ window.scrollBy(0, 100000);}, 1);</script>
- <meta http-equiv="refresh" content="1">
- </head>
- create.html
- <html><body>
- <form action = "create.php" method="POST">
- Username: <input type="text" name="login" value="" />
- <br />
- Password: <input type="password" name="passwd" value="" />
- <input type="submit" name="submit" value="OK" />
- </form>
- </body></html>
- create.php
- <?php
- function add_account($login, $passwd, $path, $accounts)
- {
- $hash = hash("whirlpool", $passwd);
- $new_account = array("login"=>$login, "passwd"=>$hash);
- $accounts[] = $new_account;
- file_put_contents($path, serialize($accounts));
- echo "OK\n";
- header("Location: index.html");
- }
- function search_account($login, $accounts)
- {
- foreach ($accounts as $elem) {
- if ($elem["login"] == $login)
- return true;
- }
- return false;
- }
- $login = $_POST['login'];
- $passwd = $_POST['passwd'];
- $submit = $_POST['submit'];
- $folder = '../private';
- $path = '../private/passwd';
- $accounts = array();
- if ($submit == 'OK')
- {
- if (!file_exists($folder))
- mkdir($folder);
- $accounts = file_get_contents($path);
- $accounts = unserialize($accounts);
- if ($passwd == NULL)
- echo "ERROR\n";
- else if ($accounts == NULL)
- add_account($login, $passwd, $path, $accounts);
- else
- {
- if (!search_account($login, $accounts))
- add_account($login, $passwd, $path, $accounts);
- else
- echo "ERROR\n";
- }
- }
- else
- echo "ERROR\n";
- ?>
- index.html
- <html><body>
- <form action="login.php" method="POST">
- Username: <input type="text" name="login" value="" />
- <br />
- Password: <input type="password" name="passwd" value="" />
- <input type="submit" name="submit" value="OK" />
- <br />
- <a href="create.html">Create an account</a>
- <br />
- <a href="modif.html">Modify the password</a>
- </form>
- </body></html>
- login.php
- <?php
- include("auth.php");
- $login = $_POST['login'];
- $passwd = $_POST['passwd'];
- session_start();
- if (auth($login, $passwd))
- {
- $_SESSION['loggued_on_user'] = $login;
- echo '<html><body>
- <iframe name="chat" src="chat.php" width="100%" height="550px"></iframe>
- <iframe name="speak" src="speak.php" width="100%" height="50px"></iframe>
- <a href="logout.php">Logout</a>
- </body></html>';
- }
- else
- {
- $_SESSION['loggued_on_user'] = "";
- echo "ERROR\n";
- }
- ?>
- logout.php
- <?php
- session_start();
- $_SESSION['loggued_on_user'] = "";
- header("Location: index.html");
- ?>
- modif.html
- <html><body>
- <form action = "modif.php" method="POST">
- Username: <input type="text" name="login" value="" />
- <br />
- Old password: <input type="password" name="oldpw" value="" />
- <br />
- New password: <input type="password" name="newpw" value="" />
- <input type="submit" name="submit" value="OK" />
- </form>
- </body></html>
- modif.php
- <?php
- function search_account($login, $oldpw, $accounts)
- {
- $hash = hash("whirlpool", $oldpw);
- foreach ($accounts as $elem) {
- if ($elem["login"] == $login && $elem["passwd"] == $hash)
- return true;
- }
- return false;
- }
- function modif_account($login, $newpw, &$accounts)
- {
- $hash = hash("whirlpool", $newpw);
- foreach ($accounts as &$elem) {
- if ($elem["login"] == $login)
- {
- $elem["passwd"] = $hash;
- return;
- }
- }
- }
- $login = $_POST['login'];
- $oldpw = $_POST['oldpw'];
- $newpw = $_POST['newpw'];
- $submit = $_POST['submit'];
- $path = '../private/passwd';
- $accounts = array();
- if ($submit == 'OK')
- {
- $accounts = file_get_contents($path);
- $accounts = unserialize($accounts);
- if ($newpw == NULL || $oldpw == NULL)
- echo "ERROR\n";
- else if ($accounts == NULL)
- echo "ERROR\n";
- else
- {
- if (!search_account($login, $oldpw, $accounts))
- echo "ERROR\n";
- else
- {
- modif_account($login, $newpw, $accounts);
- file_put_contents($path, serialize($accounts));
- echo "OK\n";
- header("Location: index.html");
- }
- }
- }
- else
- echo "ERROR\n";
- ?>
- speak.php
- <?php
- date_default_timezone_set('Europe/Bucharest');
- session_start();
- $msg = $_POST['msg'];
- $submit = $_POST['submit'];
- $folder = "../private";
- $path = "../private/chat";
- if ($submit == "OK")
- {
- if ($_SESSION['loggued_on_user'])
- {
- if (!file_exists($folder))
- mkdir($folder);
- $fp = fopen($path, "r+");
- flock($fp, LOCK_EX);
- $messages = file_get_contents($path);
- $messages = unserialize($messages);
- $new_msg = array("login"=>$_SESSION['loggued_on_user'], "time"=>date("[d/m/y H:i:s]"), "msg"=>$msg);
- $messages[] = $new_msg;
- file_put_contents($path, serialize($messages));
- fclose($fp);
- }
- else
- echo "ERROR\n";
- }
- ?>
- <form method='POST'>
- <input type='text' style='width: 250px;' name='msg'>
- <input type='submit' name='submit' value='OK'>
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement