Advertisement
Guest User

Untitled

a guest
Sep 14th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.08 KB | None | 0 0
  1. *<!DOCTYPE html>
  2. <html>
  3. <head>
  4.  
  5. <?php include $_SERVER["DOCUMENT_ROOT"] . "/assets/head.php"; ?>
  6. <title><?php echo $address; ?> - Sign In</title>
  7. </head>
  8. <body>
  9. <?php include $_SERVER["DOCUMENT_ROOT"] . "/navigationbar.php"; ?>
  10.  
  11. <div class="wrapper">
  12.  
  13. <div class="small-banner">
  14. <div id="animate-area"></div>
  15. </div>
  16.  
  17.  
  18.  
  19. <div class="tabs" id="tabs">
  20. <h1>Sign In</h1>
  21. <div class="p">
  22.  
  23.  
  24. <?php
  25. // This variable will be used to re-display the user's username to them in the
  26. // login form if they fail to enter the correct password. It is initialized here
  27. // to an empty value, which will be shown if the user has not submitted the form.
  28. $submitted_username = '';
  29.  
  30. // This if statement checks to determine whether the login form has been submitted
  31. // If it has, then the login code is run, otherwise the form is displayed
  32. if(!empty($_POST))
  33. {
  34. // This query retreives the user's information from the database using
  35. // their username.
  36. $query = "
  37. SELECT
  38. *
  39. FROM users
  40. WHERE
  41. username = :username
  42. ";
  43.  
  44. // The parameter values
  45. $query_params = array(
  46. ':username' => $_POST['username']
  47. );
  48.  
  49. try
  50. {
  51. // Execute the query against the database
  52. $stmt = $db->prepare($query);
  53. $result = $stmt->execute($query_params);
  54. }
  55. catch(PDOException $ex)
  56. {
  57. // Note: On a production website, you should not output $ex->getMessage().
  58. // It may provide an attacker with helpful information about your code.
  59. die("<div class='red'>Failed to run query: </div>" . $ex->getMessage());
  60. }
  61.  
  62. // This variable tells us whether the user has successfully logged in or not.
  63. // We initialize it to false, assuming they have not.
  64. // If we determine that they have entered the right details, then we switch it to true.
  65. $login_ok = false;
  66.  
  67. // Retrieve the user data from the database. If $row is false, then the username
  68. // they entered is not registered.
  69. $row = $stmt->fetch();
  70. if($row)
  71. {
  72. // Using the password submitted by the user and the salt stored in the database,
  73. // we now check to see whether the passwords match by hashing the submitted password
  74. // and comparing it to the hashed version already stored in the database.
  75. $check_password = hash('sha256', $_POST['password'] . $row['salt']);
  76. for($round = 0; $round < 65536; $round++)
  77. {
  78. $check_password = hash('sha256', $check_password . $row['salt']);
  79. }
  80.  
  81. if($check_password === $row['password'])
  82. {
  83. // If they do, then we flip this to true
  84. $login_ok = true;
  85. }
  86. }
  87.  
  88. // If the user logged in successfully, then we send them to the private members-only page
  89. // Otherwise, we display a login failed message and show the login form again
  90. if($login_ok)
  91. {
  92.  
  93. // Here I am preparing to store the $row array into the $_SESSION by
  94. // removing the salt and password values from it. Although $_SESSION is
  95. // stored on the server-side, there is no reason to store sensitive values
  96. // in it unless you have to. Thus, it is best practice to remove these
  97. // sensitive values first.
  98. unset($row['salt']);
  99. unset($row['password']);
  100.  
  101. // This stores the user's data into the session at the index 'user'.
  102. // We will check this index on the private members-only page to determine whether
  103. // or not the user is logged in. We can also use it to retrieve
  104. // the user's details.
  105. $_SESSION['user'] = $row;
  106.  
  107. $username = htmlentities($_POST['username'], ENT_QUOTES, 'UTF-8');
  108. $last_life_update = "UPDATE users SET last_life = now() WHERE username = '$username'";
  109. $db->query($last_life_update);
  110. // Redirect the user to the private members-only page.
  111. header("Location: /");
  112. die("Redirecting to: /");
  113.  
  114. }
  115. else
  116. {
  117. // Tell the user they failed
  118. print("<div class='red'>Login Failed.</div>");
  119.  
  120. // Show them their username again so all they have to do is enter a new
  121. // password. The use of htmlentities prevents XSS attacks. You should
  122. // always use htmlentities on user submitted values before displaying them
  123. // to any users (including the user that submitted them). For more information:
  124. // http://en.wikipedia.org/wiki/XSS_attack
  125. $submitted_username = htmlentities($_POST['username'], ENT_QUOTES, 'UTF-8');
  126. }
  127. }
  128. ?>
  129. <form mathod="post" action="" style="margin:20px;">
  130. <label for="username">Username :</label><br />
  131. <input type="text" name="username" maxlength="64" id="username" placeholder="Username" class="input-long" readonly onfocus="this.removeAttribute('readonly');"/>
  132. <div class="clear-top"></div>
  133.  
  134. <label for="password">Password :</label><br />
  135. <input type="password" name="password" id="password" placeholder="Password" class="input-long" readonly onfocus="this.removeAttribute('readonly') ;"/>
  136. <div class="clear-top"></div>
  137.  
  138. <label><input type="checkbox" name="sport[]" value="remember" /> Remember Password</label>
  139. <div class="clear-top"></div>
  140.  
  141. <input type="submit" value="Sign In" class="btn"/><br />
  142.  
  143. <a href="/forgot-password" class="link"><i style="color:#777f8c;">(Forgot password)</i></a>
  144. </form>
  145. </div>
  146. </div>
  147.  
  148. </div>
  149.  
  150. <div style="position:relative; clear:both;"></div>
  151.  
  152. <!--</body>-->
  153. <?php include $_SERVER["DOCUMENT_ROOT"] . "/footer.php"; ?>
  154. </body>
  155. </html>*
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement