Guest User

Untitled

a guest
Mar 6th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. <?php
  2. checkPass();
  3. function readFilez()
  4. {
  5. $lines = file('./passwd.txt');
  6. foreach ($lines as $line)
  7. {
  8. $line = trim($line);
  9. $username = strtok($line, ':');
  10. $password = strtok("\n");
  11. $arrayz[$username] = $password;
  12. }
  13. return $arrayz;
  14. }
  15.  
  16. function checkPass()
  17. {
  18. $arrayx = readFilez();
  19. print_r($arrayx);
  20. $user = $_POST["user"];
  21. $pass = $_POST["pw"];
  22. $file = fopen('./passwd.txt', 'r');
  23. if (!isset($_POST["user"]) || !isset($_POST["pw"]))
  24. { echo '<script type = "javascript"> alert("Please complete all fields."); </script>'; }
  25. else
  26. {
  27. foreach ($arrayx as $key => $value)
  28. {
  29. if ($user != $key)
  30. {
  31. echo '<script type = "javascript"> alert("Username does not exist."); </script>';
  32. return false;
  33. }
  34. else
  35. {
  36. if ($arrayx[$user] != $pass)
  37. {
  38. echo '<script type = "javascript"> alert("Invalid password."); </script>';
  39. return false;
  40. }
  41. else
  42. $username = $user;
  43. }
  44. }
  45. }
  46. fclose($file);
  47. }
  48.  
  49. print <<<PAGE
  50. <html>
  51. <head>
  52. <title>Login Page</title>
  53. <style type = "text/css">
  54. table
  55. {
  56. margin-left: auto;
  57. margin-right: auto;
  58. font-family: Georgia, sans-serif;
  59. font-size: 14pt;
  60. }
  61. h3
  62. {
  63. text-align: center;
  64. font-size: 16pt;
  65. }
  66. </style>
  67. </head>
  68. <body>
  69. <h3>Please sign in or create an account.</h3>
  70. <form method = "post" action = "login.php">
  71. <table>
  72. <tr>
  73. <td>Username: <input type = "text" name = "user" /></td>
  74. <td>Password: <input type = "password" name = "pw" /></td>
  75. <td>
  76. <input type = "submit" value = "Login" />
  77. <input type = "hidden" name = "username" value = "$username" />
  78. </td>
  79. </tr>
  80. </table>
  81. </form>
  82. <h3>Don't have a username? <a href = "./createaccount.php">Create an account.</a></h3>
  83. </body>
  84. </html>
  85. PAGE;
  86. ?>
Add Comment
Please, Sign In to add comment