Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. <?php
  2. require 'require/sharedVar.php';
  3. require 'require/functions.php';
  4. require 'require/connect.php';
  5. require 'require/error_reporting.php';
  6.  
  7. if (isset($_POST['login']) && trim($_POST['login']) != '') {
  8. if (isset($_POST['username']) && isset($_POST['password']) && trim($_POST['username']) != '' && trim($_POST['password']) != '') {
  9.  
  10. $username = escape_quotes($_POST['username']);
  11. $password = escape_quotes(hash("sha512", $_POST['password']));
  12.  
  13. $user = get_all_info("SELECT * FROM users WHERE Username='$username'");
  14.  
  15. // Get the first instance of the user and store it into an array
  16. $userArray = $user->fetch_assoc();
  17.  
  18. if(count($userArray) <= 0) {
  19. die("That username doesn't exist! Try making <i>$username</i> today! <a href='login.php'>Back</a>");
  20. }
  21. if ($userArray['Password'] != $password) {
  22. die("Incorrect password! <a href='login.php'>Back</a>");
  23. }
  24. $salt = hash("sha512", rand() . rand() . rand());
  25.  
  26. setcookie("c_user", hash("sha512", $username), time() + 24 * 60 * 60, "/");
  27. setcookie("c_salt", $salt, time() + 24 * 60 * 60, "/");
  28.  
  29. $userID = $userArray['ID'];
  30. insert_or_update_info("UPDATE users SET Salt='$salt' WHERE ID='$userID'");
  31.  
  32. die("You are now logged in as $username");
  33. }
  34. else {
  35. echo "Please enter a username and password.";
  36. }
  37. }
  38.  
  39. ?>
  40. <!doctype html>
  41. <html>
  42. <head>
  43. <?php include "includes/head.php" ?>
  44. </head>
  45. <body>
  46. <div id="container">
  47. <?php include "includes/header.php" ?>
  48. <?php include "includes/nav.php" ?>
  49.  
  50. <form method="post" action="">
  51. <ul>
  52. <li>
  53. <label for="username">Username</label>
  54. <input id="username" type="text" name="username" value="" />
  55. </li>
  56. <li>
  57. <label for="password">Password</label>
  58. <input id="password" type="password" name="password" value=""/>
  59. <li>
  60. <input type="submit" name="login" value="Login">
  61. </li>
  62. </ul>
  63. </form>
  64.  
  65. <?php include 'includes/footer.php' ?>
  66. </div>
  67. <h2>Haven't Registered? Register<a href="register.php"> here</a></h4>
  68. </body>
  69. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement