Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <!--
- -->
- <html>
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" type="text/css" href="footer2.css">
- <title> webbutveckling 2</title>
- </head>
- <body>
- <?php
- session_start();
- $user_username = $_POST['userName'];
- $user_password = $_POST['password'];
- $password_hashed = password_hash($user_password, PASSWORD_DEFAULT);
- $file = 'useraccounts.txt';
- $success = false;
- if(isset($_POST['submit_button2'])){
- echo "Du har nu loggat ut", $_SESSION['sessionID'];
- session_abort();
- }
- if (isset($_POST['submit_button1'])) {
- if (file_exists($file)) {
- $content = file_get_contents($file);
- $content = explode("\n", $content);
- foreach ($content as $value) {
- $user = explode(':', $value);
- if ($user[0] == $user_username && (password_verify($user[1], $password_hashed))){
- $success = true;
- break;
- }
- }
- }
- if ($success) {
- $_SESSION['sessionID'] = $user_username;
- //echo "<br> Hi $user_username you have been logged in. this is PW: $user_password. this is hashed: $password_hashed <br>";
- echo "You are logged in right now: ", $_SESSION['sessionID'];
- } else {
- echo "<br> You have entered the wrong username or password. Please try again. <br>";
- }
- }
- include 'footer2.php';
- ?>
- <form action="login.php" method="post">
- <br>
- <input type="submit" name="submit_button2" value="Logga ut">
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement