Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.32 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Login...</title>
  6. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  7. <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
  8. </head>
  9. <body>
  10. <?php
  11. session_start();
  12. session_unset();
  13. if(isset($_COOKIE["CU"]) and isset($_COOKIE["CP"])) {
  14. $username=$_COOKIE["CU"];
  15. $password=$_COOKIE["CP"];
  16. }
  17. ?>
  18. <form class="needs-validation" action="login.php" method="POST" novalidate>
  19. <div class="form-column">
  20. <div class="col-md-4 mb-3">
  21. <label for="validationCustom01">E-mail</label>
  22. <input type="email" class="form-control" name="mail" placeholder="E-mail" value="<?php if(isset($username)) echo $username;?>" required>
  23.  
  24. <div class="invalid-feedback">
  25. Wrong pattern!
  26. </div>
  27. </div>
  28. <div class="col-md-4 mb-3">
  29. <label for="validationCustom02">password</label>
  30. <input type="password" class="form-control" name="password" placeholder="Password" value="<?php if(isset($password)) echo $password;?>" required>
  31. <div class="invalid-feedback">
  32. Wrong pattern!
  33. </div>
  34. </div>
  35. </div>
  36.  
  37. <div class="form-group">
  38. <div class="custom-control custom-checkbox">
  39. <?php
  40. if(isset($_COOKIE["CU"]) and isset($_COOKIE["CP"])) {
  41. echo "<input type=\"checkbox\" class=\"custom-control-input\" id=\"customCheck1\" name=\"customCheck1\" checked=\"true\">";
  42. }else{
  43. echo "<input type=\"checkbox\" class=\"custom-control-input\" id=\"customCheck1\" name=\"customCheck1\">";
  44. }
  45. ?>
  46. <label class="custom-control-label" for="customCheck1">Remember me</label>
  47. </div>
  48. </div>
  49. <button class="btn btn-primary" type="submit" >Login</button>
  50. </form>
  51.  
  52. <script>
  53. // Example starter JavaScript for disabling form submissions if there are invalid fields
  54. function check() {
  55. var check=document.getElementById("customCheck1");
  56. alert(check.checked);
  57. }
  58. (function() {
  59. 'use strict';
  60. window.addEventListener('load', function() {
  61. // Fetch all the forms we want to apply custom Bootstrap validation styles to
  62. var forms = document.getElementsByClassName('needs-validation');
  63. // Loop over them and prevent submission
  64. var validation = Array.prototype.filter.call(forms, function(form) {
  65. form.addEventListener('submit', function(event) {
  66. if (form.checkValidity() === false) {
  67. event.preventDefault();
  68. event.stopPropagation();
  69. }
  70. form.classList.add('was-validated');
  71. }, false);
  72. });
  73. }, false);
  74. })();
  75. </script>
  76.  
  77. </body>
  78. </html>
  79. <?php
  80. if($_SERVER["REQUEST_METHOD"] == "POST")
  81. {
  82. require_once 'config.php';
  83. $username=$_POST['mail'];
  84. $password=$_POST['password'];
  85. if(isset($_POST['customCheck1']))
  86. {
  87. setcookie("CU", $username, time() + (86400 * 30), "/");
  88. setcookie("CP", $password, time() + (86400 * 30), "/");
  89. }else
  90. {
  91. setcookie("CU", $username, time()- 1, "/");
  92. setcookie("CP", $password, time()- 1, "/");
  93. }
  94. $sql="select * from users where username=:username";
  95. $stmt= $pdo->prepare($sql);
  96. $stmt->bindParam(':username',$username,PDO::PARAM_STR);
  97. $stmt->execute();
  98. if($stmt->rowCount() == 1)
  99. {
  100. $row= $stmt->fetch();
  101. $hasspassword=$row['password'];
  102.  
  103. if(password_verify($password, $hasspassword)) //---login with hash
  104. {
  105. if(isset($_POST['rememberMe'])){
  106. setcookie('username',$username,time() + (86400 * 30)) ;
  107. setcookie('password',$password,time() + (86400 * 30)) ;
  108. }else{
  109. setcookie('username',$username,time()-1) ;
  110. setcookie('password',$password,time()-1) ;
  111. }
  112. session_start();
  113. $_SESSION['username']= $username;
  114. header('Location:mytable.php');
  115. }
  116. else
  117. header('Location:login.php');
  118. }
  119. }
  120. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement