Advertisement
Guest User

Basic Login Form

a guest
Mar 30th, 2018
692
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1. <!-- Login Page -->
  2.  
  3.  
  4. <html>
  5. <head>
  6. <title>Welcome</title>
  7. </head>
  8. <body>
  9.  
  10.  
  11.  
  12.  
  13. <form action="project.php" method="POST">
  14.         Username: <input type="text" name="username"/>
  15.         Password: <input type="password" name="password"/>
  16.         <input type="submit" value="Submit"/>
  17. </form>
  18.  
  19.  
  20. </body>
  21.  
  22. </html>
  23.  
  24.  
  25.  
  26. index.php                                                                                                                                                                                        1,19           All
  27. <!-- Login Attempt Page -->
  28.  
  29. <?php
  30.  
  31. $username = $_POST['username'];
  32. $pass = $_POST['password'];
  33. $hash = password_hash($pass, PASSWORD_DEFAULT);
  34.  
  35.  
  36. if ($username == 'alex' && $pass == 'genesis') {
  37.         echo "You have successfully logged in!";
  38.         $path = $_SERVER['DOCUMENT_ROOT'] . '/project/credentials/hashed_password.txt';
  39.         $f = fopen($path, 'w');
  40.         fwrite($f, $hash);
  41.         fclose($f);
  42. } else {
  43.         echo "Wrong username or password";
  44. }
  45.  
  46.  
  47. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement