Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Login...</title>
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
- <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
- </head>
- <body>
- <?php
- session_start();
- session_unset();
- if(isset($_COOKIE["CU"]) and isset($_COOKIE["CP"])) {
- $username=$_COOKIE["CU"];
- $password=$_COOKIE["CP"];
- }
- ?>
- <form class="needs-validation" action="login.php" method="POST" novalidate>
- <div class="form-column">
- <div class="col-md-4 mb-3">
- <label for="validationCustom01">E-mail</label>
- <input type="email" class="form-control" name="mail" placeholder="E-mail" value="<?php if(isset($username)) echo $username;?>" required>
- <div class="invalid-feedback">
- Wrong pattern!
- </div>
- </div>
- <div class="col-md-4 mb-3">
- <label for="validationCustom02">password</label>
- <input type="password" class="form-control" name="password" placeholder="Password" value="<?php if(isset($password)) echo $password;?>" required>
- <div class="invalid-feedback">
- Wrong pattern!
- </div>
- </div>
- </div>
- <div class="form-group">
- <div class="custom-control custom-checkbox">
- <?php
- if(isset($_COOKIE["CU"]) and isset($_COOKIE["CP"])) {
- echo "<input type=\"checkbox\" class=\"custom-control-input\" id=\"customCheck1\" name=\"customCheck1\" checked=\"true\">";
- }else{
- echo "<input type=\"checkbox\" class=\"custom-control-input\" id=\"customCheck1\" name=\"customCheck1\">";
- }
- ?>
- <label class="custom-control-label" for="customCheck1">Remember me</label>
- </div>
- </div>
- <button class="btn btn-primary" type="submit" >Login</button>
- </form>
- <script>
- // Example starter JavaScript for disabling form submissions if there are invalid fields
- function check() {
- var check=document.getElementById("customCheck1");
- alert(check.checked);
- }
- (function() {
- 'use strict';
- window.addEventListener('load', function() {
- // Fetch all the forms we want to apply custom Bootstrap validation styles to
- var forms = document.getElementsByClassName('needs-validation');
- // Loop over them and prevent submission
- var validation = Array.prototype.filter.call(forms, function(form) {
- form.addEventListener('submit', function(event) {
- if (form.checkValidity() === false) {
- event.preventDefault();
- event.stopPropagation();
- }
- form.classList.add('was-validated');
- }, false);
- });
- }, false);
- })();
- </script>
- </body>
- </html>
- <?php
- if($_SERVER["REQUEST_METHOD"] == "POST")
- {
- require_once 'config.php';
- $username=$_POST['mail'];
- $password=$_POST['password'];
- if(isset($_POST['customCheck1']))
- {
- setcookie("CU", $username, time() + (86400 * 30), "/");
- setcookie("CP", $password, time() + (86400 * 30), "/");
- }else
- {
- setcookie("CU", $username, time()- 1, "/");
- setcookie("CP", $password, time()- 1, "/");
- }
- $sql="select * from users where username=:username";
- $stmt= $pdo->prepare($sql);
- $stmt->bindParam(':username',$username,PDO::PARAM_STR);
- $stmt->execute();
- if($stmt->rowCount() == 1)
- {
- $row= $stmt->fetch();
- $hasspassword=$row['password'];
- if(password_verify($password, $hasspassword)) //---login with hash
- {
- if(isset($_POST['rememberMe'])){
- setcookie('username',$username,time() + (86400 * 30)) ;
- setcookie('password',$password,time() + (86400 * 30)) ;
- }else{
- setcookie('username',$username,time()-1) ;
- setcookie('password',$password,time()-1) ;
- }
- session_start();
- $_SESSION['username']= $username;
- header('Location:mytable.php');
- }
- else
- header('Location:login.php');
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement