Advertisement
Guest User

Untitled

a guest
May 14th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. //login.functions.inc.php
  2.  
  3. <?php
  4.  
  5. #### Login Functions #####
  6.  
  7.  
  8. function isLoggedIn()
  9. {
  10.  
  11. if (session_is_registered('loginid') && session_is_registered('username'))
  12. {
  13. return true; // the user is loged in
  14. } else
  15. {
  16. return false; // not logged in
  17. }
  18.  
  19. return false;
  20.  
  21. }
  22.  
  23. function checkLogin($u, $p)
  24. {
  25. global $seed; // global because $seed is declared in the header.php file
  26.  
  27. if (!valid_username($u) || !valid_password($p) || !user_exists($u))
  28. {
  29. return false; // the name was not valid, or the password, or the username did not exist
  30. }
  31.  
  32. //Now let us look for the user in the database.
  33. $query = sprintf("
  34. SELECT loginid
  35. FROM login
  36. WHERE
  37. username = '%s' AND password = '%s'
  38. LIMIT 1;", mysql_real_escape_string($u), mysql_real_escape_string(sha1($p . $seed)));
  39. $result = mysql_query($query);
  40. // If the database returns a 0 as result we know the login information is incorrect.
  41. // If the database returns a 1 as result we know the login was correct and we proceed.
  42. // If the database returns a result > 1 there are multple users
  43. // with the same username and password, so the login will fail.
  44. if (mysql_num_rows($result) != 1)
  45. {
  46. return false;
  47. } else
  48. {
  49. // Login was successfull
  50. $row = mysql_fetch_array($result);
  51. // Save the user ID for use later
  52. $_SESSION['loginid'] = $row['loginid'];
  53. // Save the username for use later
  54. $_SESSION['username'] = $u;
  55. // Now we show the userbox
  56. return true;
  57. }
  58. return false;
  59. }
  60.  
  61. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement