A unf. social network done poorly.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
2.0KB

  1. <?php
  2. error_reporting(E_ALL);
  3. ini_set('display_errors', '1');
  4. require_once($_SERVER['DOCUMENT_ROOT'] . '/socialtune/includes/session.php');
  5. require_once($_SERVER['DOCUMENT_ROOT'] . '/socialtune/includes/config.php');
  6. $email = (!empty($_POST['email'])) ? $_POST['email'] : false;
  7. $password = (!empty($_POST['password'])) ? $_POST['password'] : false;
  8. if($email && $password){
  9. $connection = mysqli_connect($dbHost, $dbUser, $dbPass, $dbName);
  10. $email = mysqli_real_escape_string($connection, $email);
  11. $password = mysqli_real_escape_string($connection, $password);
  12. $query = "SELECT * FROM users WHERE email='$email'";
  13. $result = mysqli_query($connection, $query);
  14. if($result){
  15. $row = mysqli_fetch_array($result);
  16. $storedHash = $row[2];
  17. }
  18. $validateHash = $salt . $storedHash;
  19. for($i = 0; $i < 1; $i++){ $validateHash = hash('sha256', $validateHash);}
  20. $validateHash = $salt. $validateHash;
  21. $validateHash = substr($storedHash,0,64);
  22. $enteredHash = $salt . $password;
  23. for($i = 0; $i < 1; $i++){ $enteredHash = hash('sha256', $enteredHash);} // Look. Tiny code. I hope it's not too hard to understand. :|
  24. $userEnteredHash = substr($enteredHash,0,64);
  25. if($enteredHash == $validateHash){
  26. $_SESSION['username'] = $email;
  27. $_SESSION['password'] = $password;
  28. $_SESSION['Authenticated'] = true;
  29. $_SESSION['Expires'] = time() + 86400; // 24 hours.
  30. $_SESSION['isOnline'] = True; // omfg.
  31. $numberOne = 1;
  32. $isOnline = "UPDATE users SET isOnline='$numberOne' WHERE email='$email'";
  33. // Make online = True
  34. if(mysqli_query($connection, $isOnline)){
  35. echo 'User is online.';
  36. }else{
  37. echo 'Something went wrong...';
  38. }
  39. echo "Log in succesful.<br>Loading dashboard.";
  40. header("Location: dashboard.php");
  41. }else{header("Location: index.php?q=3");} // validated incorrectly.
  42. mysqli_close($connection);
  43. }else{ header("Location: index.php?q=2");} // Forgot to pass either: email || pass
  44. ?>