Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. <?php
  2. //session_start();
  3. /*
  4. * To be able to login the following things need to be true
  5. * correct username/password
  6. * username must be validated
  7. * username must not be marked as logged in?
  8. */
  9. require_once("mysql.php");
  10. mysqlConnect();
  11. //checkCreds();
  12.  
  13. function checkCreds($user, $pass){
  14. //login
  15. //echo "User: $user Pass: $pass #";
  16. $result = mysql_query("SELECT * FROM user WHERE username = \"$user\"");
  17. $row = mysql_fetch_array($result);
  18.  
  19. if ($row['password'] == $pass){ //correct password for the user
  20. $_SESSION['uName'] = $user;
  21. mysql_query("UPDATE user SET sessionID = \"".session_id()."\" WHERE username = $user");
  22. isLoggedIn($user);
  23.  
  24. }else{//bad password
  25. isLoggedIn("");
  26. }
  27. }
  28.  
  29.  
  30. function isLoggedIn($uname){
  31. //if the user is logged in, then display a welcome message
  32. if ($uname == ""){
  33. //user is not logged in
  34. echo "<div id=\"login2\">";
  35. echo "<form action=\"serverside/login.php\" method=\"post\">";
  36. echo "Username: ";
  37. echo "<input type=\"text\" name=\"uname\" id=\"loginUname\" class=\"loginField\">";
  38. echo "Password: ";
  39. echo "<input type=\"password\" name=\"pass\" id=\"loginPass\" class=\"loginField\">";
  40. echo "<input type=\"button\" value=\"Submit\" onclick=\"mycatch()\" class=\"loginField\"/>";
  41. echo "</form>";
  42. echo "<a href=\"password.php\">Forgot your password?</a><br />";
  43. echo "<a href=\"register.php\">Register as a new user</a>";
  44. echo "</div>";
  45. }else{
  46. //TODO:
  47. //check that the username, and session id are correct
  48. //ie. upon logging in the db will store the (then) current session id
  49. //we can check that session id + name each time we send a page
  50. //will cost as an extra lookup, but is more secure (session cookie hasn't been messed with to trick us into thinking it's for a logged in user)
  51.  
  52. echo "Welcome ".$uname;
  53. }
  54. //$ip= $_SERVER['REMOTE_ADDR'];
  55. //echo "<b>IP Address= $ip#</b>";
  56. }
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement