An PHP based Image Database
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.

52 lines
2.3 KiB

  1. <?
  2. //
  3. // Copyright (c) 2013 Mr. Gecko's Media (James Coleman). http://mrgeckosmedia.com/
  4. //
  5. // Permission to use, copy, modify, and/or distribute this software for any purpose
  6. // with or without fee is hereby granted, provided that the above copyright notice
  7. // and this permission notice appear in all copies.
  8. //
  9. // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  10. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  11. // FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  12. // OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  14. // ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. //
  16. $error = "";
  17. if (isset($_REQUEST['login'])) {
  18. $email = (isset($_REQUEST['email']) ? trim($_REQUEST['email']) : "");
  19. $password = (isset($_REQUEST['password']) ? trim($_REQUEST['password']) : "");
  20. $result = databaseQuery("SELECT * FROM users WHERE email=%s AND level!=0", $email);
  21. $user = databaseFetchAssoc($result);
  22. if ($user==NULL) {
  23. $error = "Invalid login credentials.";
  24. } else {
  25. $salt = substr($user['password'], 0, 12);
  26. $epassword = $salt.hashPassword($password,hex2bin($salt));
  27. if ($epassword!=$user['password']) {
  28. $error = "Invalid login credentials.";
  29. } else {
  30. databaseQuery("UPDATE users SET time=%d WHERE email=%s", $_MGM['time'], $email);
  31. setcookie("{$_MGM['CookiePrefix']}user_email", $email, $_MGM['time']+31536000, $_MGM['CookiePath'], $_MGM['CookieDomain']);
  32. setcookie("{$_MGM['CookiePrefix']}user_password", hash("sha512", $epassword.$_MGM['time']), $_MGM['time']+31536000, $_MGM['CookiePath'], $_MGM['CookieDomain']);
  33. header("location: ".generateURL());
  34. exit();
  35. }
  36. }
  37. }
  38. require_once("header.php");
  39. if (!empty($error)) {
  40. ?><div style="color: #ff0000; font-weight: bold;"><?=$error?></div><?
  41. }
  42. ?>
  43. <form action="<?=generateURL("login")?>" method="POST">
  44. <input type="hidden" name="login" value="true" />
  45. <input type="text" placeholder="Email" name="email" /><br />
  46. <input type="password" placeholder="Password" name="password" /><br />
  47. <input type="submit" value="Login" class="btn" />
  48. </form>
  49. <?
  50. require_once("footer.php");
  51. exit();
  52. ?>