Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //login.php
- /**
- * Start the session.
- */
- session_start();
- /**
- * Include ircmaxell's password_compat library.
- */
- require 'lib/password.php';
- /**
- * Include our MySQL connection.
- */
- require 'connect.php';
- //If the POST var "login" exists (our submit button), then we can
- //assume that the user has submitted the login form.
- if(isset($_POST['login'])){
- //Retrieve the field values from our login form.
- $username = !empty($_POST['username']) ? trim($_POST['username']) : null;
- $passwordAttempt = !empty($_POST['password']) ? trim($_POST['password']) : null;
- //Retrieve the user account information for the given username.
- $sql = "SELECT id, username, password FROM users WHERE username = :username";
- $stmt = $pdo->prepare($sql);
- //Bind value.
- $stmt->bindValue(':username', $username);
- //Execute.
- $stmt->execute();
- //Fetch row.
- $user = $stmt->fetch(PDO::FETCH_ASSOC);
- //If $row is FALSE.
- if($user === false){
- //Could not find a user with that username!
- //PS: You might want to handle this error in a more user-friendly manner!
- die('Incorrect username / password combination!');
- } else{
- //User account found. Check to see if the given password matches the
- //password hash that we stored in our users table.
- //Compare the passwords.
- $validPassword = password_verify($passwordAttempt, $user['password']);
- //If $validPassword is TRUE, the login has been successful.
- if($validPassword){
- //Provide the user with a login session.
- $_SESSION['user_id'] = $user['id'];
- $_SESSION['logged_in'] = time();
- //Redirect to our protected page, which we called home.php
- header('Location: home.php');
- exit;
- } else{
- //$validPassword was FALSE. Passwords do not match.
- die('Incorrect username / password combination!');
- }
- }
- }
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>Login V20</title>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <!--===============================================================================================-->
- <link rel="icon" type="image/png" href="images/icons/favicon.ico"/>
- <!--===============================================================================================-->
- <link rel="stylesheet" type="text/css" href="vendor/bootstrap/css/bootstrap.min.css">
- <!--===============================================================================================-->
- <link rel="stylesheet" type="text/css" href="fonts/font-awesome-4.7.0/css/font-awesome.min.css">
- <!--===============================================================================================-->
- <link rel="stylesheet" type="text/css" href="fonts/Linearicons-Free-v1.0.0/icon-font.min.css">
- <!--===============================================================================================-->
- <link rel="stylesheet" type="text/css" href="vendor/animate/animate.css">
- <!--===============================================================================================-->
- <link rel="stylesheet" type="text/css" href="vendor/css-hamburgers/hamburgers.min.css">
- <!--===============================================================================================-->
- <link rel="stylesheet" type="text/css" href="vendor/animsition/css/animsition.min.css">
- <!--===============================================================================================-->
- <link rel="stylesheet" type="text/css" href="vendor/select2/select2.min.css">
- <!--===============================================================================================-->
- <link rel="stylesheet" type="text/css" href="vendor/daterangepicker/daterangepicker.css">
- <!--===============================================================================================-->
- <link rel="stylesheet" type="text/css" href="css/util.css">
- <link rel="stylesheet" type="text/css" href="css/main.css">
- <!--===============================================================================================-->
- </head>
- <body>
- <div class="limiter">
- <div class="container-login100">
- <div class="wrap-login100 p-b-160 p-t-50">
- <form class="login100-form validate-form">
- <span class="login100-form-title p-b-43">
- Account Login
- </span>
- <div class="wrap-input100 rs1 validate-input" data-validate = "Username is required">
- <input class="input100" type="text" name="username">
- <span class="label-input100">Username</span>
- </div>
- <div class="wrap-input100 rs2 validate-input" data-validate="Password is required">
- <input class="input100" type="password" name="pass">
- <span class="label-input100">Password</span>
- </div>
- <div class="container-login100-form-btn">
- <button class="login100-form-btn" type ="submit" name="login" value="Login" >
- Sign in
- </button>
- </div>
- <div class="text-center w-full p-t-23">
- <a href="#" class="txt1">
- Forgot password?
- </a>
- </div>
- </form>
- </div>
- </div>
- </div>
- <!--===============================================================================================-->
- <script src="vendor/jquery/jquery-3.2.1.min.js"></script>
- <!--===============================================================================================-->
- <script src="vendor/animsition/js/animsition.min.js"></script>
- <!--===============================================================================================-->
- <script src="vendor/bootstrap/js/popper.js"></script>
- <script src="vendor/bootstrap/js/bootstrap.min.js"></script>
- <!--===============================================================================================-->
- <script src="vendor/select2/select2.min.js"></script>
- <!--===============================================================================================-->
- <script src="vendor/daterangepicker/moment.min.js"></script>
- <script src="vendor/daterangepicker/daterangepicker.js"></script>
- <!--===============================================================================================-->
- <script src="vendor/countdowntime/countdowntime.js"></script>
- <!--===============================================================================================-->
- <script src="js/main.js"></script>
- </body>
- </html>
Add Comment
Please, Sign In to add comment