Guest User

Untitled

a guest
May 22nd, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. <?php
  2. function loggedIn() {
  3. if(isset($_COOKIE['username']) && isset($_COOKIE['password'])) {
  4. if(verify($_COOKIE['username'], $_COOKIE['password'])) {
  5. return true;
  6. } else {
  7. return false;
  8. }
  9. }
  10. }
  11.  
  12. function verify($user, $pass) {
  13. if($user == "haykuro") {
  14. if($pass == "mypass") {
  15. return true;
  16. } else {
  17. return false;
  18. }
  19. } else if($user == "s0cket") {
  20. if($pass == "+h25stN%") {
  21. return true;
  22. } else {
  23. return false;
  24. }
  25. } else {
  26. return false;
  27. }
  28. }
  29.  
  30. if(loggedIn()) {
  31. if(isset($_GET['page'])) {
  32. $page = htmlentities($_GET['page']);
  33. if($page == "logout") {
  34. setcookie("username", "", time() - 3600);
  35. setcookie("password", "", time() - 3600);
  36. $output = "Successfully logged out! <a href=\"admin.php\">Please click here to continue!</a><br />";
  37. } else {
  38. $output = "Please choose an option from above!";
  39. }
  40. } else {
  41. $output = "Please choose an option from above!";
  42. }
  43. $username = htmlentities($_COOKIE['username']);
  44. echo "Welcome to the admin panel, <strong>{$username}</strong><br />";
  45. echo "<a href=\"admin.php?page=logout\">Logout</a><br />";
  46. if(isset($output)) { echo $output; }
  47. } else {
  48. if(isset($_POST['dologin']) && isset($_POST['username']) && isset($_POST['password'])) {
  49. if(verify($_POST['username'], $_POST['password'])) {
  50. if(setcookie("username", $_POST['username'])) {
  51. if(setcookie("password", $_POST['password'])) {
  52. echo "Successfully logged in.<br /><a href=\"admin.php\">Please click here to continue.</a>";
  53. } else {
  54. echo "Sorry, failed to login.";
  55. }
  56. } else {
  57. echo "Sorry, failed to login.";
  58. }
  59. } else {
  60. echo "Sorry, invalid credentials provided.";
  61. }
  62. } else {
  63. ?>
  64. <form action="" method="post">
  65. Username: <input type="text" name="username" /><br />
  66. Password: <input type="password" name="password" /><br />
  67. <input type="submit" value="Login" name="dologin" />
  68. </form>
  69. <?php
  70. }
  71. }
  72. ?>
Add Comment
Please, Sign In to add comment