Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- checkPass();
- function readFilez()
- {
- $lines = file('./passwd.txt');
- foreach ($lines as $line)
- {
- $line = trim($line);
- $username = strtok($line, ':');
- $password = strtok("\n");
- $arrayz[$username] = $password;
- }
- return $arrayz;
- }
- function checkPass()
- {
- $arrayx = readFilez();
- print_r($arrayx);
- $user = $_POST["user"];
- $pass = $_POST["pw"];
- $file = fopen('./passwd.txt', 'r');
- if (!isset($_POST["user"]) || !isset($_POST["pw"]))
- { echo '<script type = "javascript"> alert("Please complete all fields."); </script>'; }
- else
- {
- foreach ($arrayx as $key => $value)
- {
- if ($user != $key)
- {
- echo '<script type = "javascript"> alert("Username does not exist."); </script>';
- return false;
- }
- else
- {
- if ($arrayx[$user] != $pass)
- {
- echo '<script type = "javascript"> alert("Invalid password."); </script>';
- return false;
- }
- else
- $username = $user;
- }
- }
- }
- fclose($file);
- }
- print <<<PAGE
- <html>
- <head>
- <title>Login Page</title>
- <style type = "text/css">
- table
- {
- margin-left: auto;
- margin-right: auto;
- font-family: Georgia, sans-serif;
- font-size: 14pt;
- }
- h3
- {
- text-align: center;
- font-size: 16pt;
- }
- </style>
- </head>
- <body>
- <h3>Please sign in or create an account.</h3>
- <form method = "post" action = "login.php">
- <table>
- <tr>
- <td>Username: <input type = "text" name = "user" /></td>
- <td>Password: <input type = "password" name = "pw" /></td>
- <td>
- <input type = "submit" value = "Login" />
- <input type = "hidden" name = "username" value = "$username" />
- </td>
- </tr>
- </table>
- </form>
- <h3>Don't have a username? <a href = "./createaccount.php">Create an account.</a></h3>
- </body>
- </html>
- PAGE;
- ?>
Add Comment
Please, Sign In to add comment