Advertisement
Guest User

Untitled

a guest
Jan 14th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. <?php
  2. /////////////////////////////////////////////////////////
  3. session_start();
  4. require 'functions.php';
  5. /////////////////////////////////////////////////////////
  6. if ( isset($_COOKIE['key']) && isset($_COOKIE['idsc'] ) ) {
  7. $id = $_COOKIE['key'];
  8. $user = $_COOKIE['idsc'];
  9.  
  10. $result = mysqli_query($conn, "SELECT username FROM users WHERE id = $id");
  11. $row = mysqli_fetch_assoc($result);
  12.  
  13. //////
  14. if ( $user === hash('sha256' , $row['username']) ) {
  15. $_SESSION['login'] = true;
  16.  
  17. }
  18. }
  19. /////////////////////////////////////////////////////////
  20. if ( isset($_SESSION['login'])) {
  21. header("Location: homepage.php");
  22. exit(0);
  23. }
  24. /////////////////////////////////////////////////////////
  25. if ( isset($_POST["login"]) ) {
  26. $username = $_POST["username"];
  27. $password = $_POST["password"];
  28.  
  29. $result = mysqli_query($conn, "SELECT * FROM users WHERE username = '$username'");
  30. //////
  31. if ( mysqli_num_rows($result) === 1){
  32.  
  33. $row = mysqli_fetch_assoc($result);
  34. //////
  35. if( password_verify($password , $row["password"] ) ){
  36.  
  37. $_SESSION["login"] = true;
  38. //////
  39. if ( isset($_POST['remember'])) {
  40.  
  41. setcookie('key' , $row['id'], time()+60);
  42. setcookie('idsc' ,hash(sha256, $row['username']),time()+60);
  43. }
  44. header("Location: homepage.php");
  45. exit(0);
  46. }
  47. }
  48.  
  49. $error = true;
  50.  
  51. }
  52. /////////////////////////////////////////////////////////
  53. ?>
  54. <!DOCTYPE html>
  55. <html>
  56. <head>
  57. <title></title>
  58. <link rel="stylesheet" href="login.css">
  59. </head>
  60. <body>
  61. <div class="logo"><img src="" alt="" id=""></div>
  62. <div class="loginform">
  63. <form action="" method="POST">
  64. <label for="username" id="user">Username : </label><input id="username" type="text" name="username" autofocus="true" required>
  65. <label for="password" id="pass">Password : </label><input id="password" type="password" placeholder="***********" name="password" required>
  66. <button type="submit" name="login" class="login">Login</button>
  67. <div id="remember">
  68. <input type="checkbox" name="remember"> <label for="remember">remember me </label>
  69. </div>
  70. </form>
  71. <div class="invite">Do you have the account? if don't , <a href="register.php">Register Here</a></div>
  72. </div>
  73. <?php
  74. if( isset($error) ) :
  75. ?>
  76. <?php endif; ?>
  77. </body>
  78. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement