1<?php
2session_start();
3?>
4<!DOCTYPE html>
5<html lang="en">
6<head>
7 <meta charset="UTF-8">
8 <meta name="viewport" content="width=device-width, initial-scale=1.0">
9 <title>Login</title>
10</head>
11<body>
12 <form action="" method="POST">
13 <input type="password" name="password">
14 <button type="submit" name="submit">Login</button>
15 </form>
16 <?php
17 if(isset($_POST['submit'])){
18 if(password_verify($_POST['password'], '$2y$10$sejeRNYZGaoPh1EwfcuO1.hxl/uepQOh9SITWWgeej86vnMt26KIa')){
19 $_SESSION['login'] = true;
20 header("Location: http://localhost");
21 }
22 }
23?>
24</body>
25</html>
1<?php
2session_start();
3$errorMsg = "";
4$validUser = $_SESSION["login"] === true;
5if(isset($_POST["sub"])) {
6 $validUser = $_POST["username"] == "admin" && $_POST["password"] == "password";
7 if(!$validUser) $errorMsg = "Invalid username or password.";
8 else $_SESSION["login"] = true;
9}
10if($validUser) {
11 header("Location: /login-success.php"); die();
12}
13?>
14<!DOCTYPE html>
15<html>
16<head>
17 <meta http-equiv="content-type" content="text/html;charset=utf-8" />
18 <title>Login</title>
19</head>
20<body>
21 <form name="input" action="" method="post">
22 <label for="username">Username:</label><input type="text" value="<?= $_POST["username"] ?>" id="username" name="username" />
23 <label for="password">Password:</label><input type="password" value="" id="password" name="password" />
24 <div class="error"><?= $errorMsg ?></div>
25 <input type="submit" value="Home" name="sub" />
26 </form>
27</body>
28</html>
29