Advertisement
Guest User

LoggedInPage

a guest
Mar 7th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.71 KB | None | 0 0
  1.  
  2. <!DOCTYPE html>
  3. <!--
  4.  
  5. -->
  6. <html>
  7. <head>
  8.     <meta charset="UTF-8">
  9.     <meta name="viewport" content="width=device-width, initial-scale=1">
  10.     <link rel="stylesheet" type="text/css" href="footer2.css">
  11.     <title> webbutveckling 2</title>
  12.  
  13.  
  14. </head>
  15. <body>
  16.  
  17. <?php
  18.     session_start();
  19.     $user_username = $_POST['userName'];
  20.     $user_password = $_POST['password'];
  21.     $password_hashed = password_hash($user_password, PASSWORD_DEFAULT);
  22.  
  23.     $file = 'useraccounts.txt';
  24.     $success = false;
  25.  
  26.     if(isset($_POST['submit_button2'])){
  27.         echo "Du har nu loggat ut", $_SESSION['sessionID'];
  28.         session_abort();
  29.     }
  30.  
  31.     if (isset($_POST['submit_button1'])) {
  32.  
  33.         if (file_exists($file)) {
  34.             $content = file_get_contents($file);
  35.             $content = explode("\n", $content);
  36.  
  37.             foreach ($content as $value) {
  38.                 $user = explode(':', $value);
  39.                 if ($user[0] == $user_username && (password_verify($user[1], $password_hashed))){
  40.                     $success = true;
  41.                     break;
  42.                 }
  43.             }
  44.         }
  45.  
  46.         if ($success) {
  47.             $_SESSION['sessionID'] = $user_username;
  48.             //echo "<br> Hi $user_username you have been logged in. this is PW: $user_password. this is hashed: $password_hashed <br>";
  49.             echo "You are logged in right now: ",  $_SESSION['sessionID'];
  50.  
  51.         } else {
  52.             echo "<br> You have entered the wrong username or password. Please try again. <br>";
  53.         }
  54.     }
  55.  
  56. include 'footer2.php';
  57.  
  58. ?>
  59.  
  60. <form action="login.php" method="post">
  61.     <br>
  62.     <input type="submit" name="submit_button2" value="Logga ut">
  63. </form>
  64.  
  65. </body>
  66. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement