Advertisement
dimaslanjaka

pw

Sep 29th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.62 KB | None | 0 0
  1. <?php
  2. header("X-Robots-Tag: noindex, nofollow", true);
  3.  
  4. ###############################################################
  5. # Page Password Protect 2.13
  6. ###############################################################
  7. # Visit http://www.zubrag.com/scripts/ for updates
  8. ###############################################################
  9. #
  10. # Usage:
  11. # Set usernames / passwords below between SETTINGS START and SETTINGS END.
  12. # Open it in browser with "help" parameter to get the code
  13. # to add to all files being protected.
  14. #    Example: password_protect.php?help
  15. # Include protection string which it gave you into every file that needs to be protected
  16. #
  17. # Add following HTML code to your page where you want to have logout link
  18. # <a href="http://www.example.com/path/to/protected/page.php?logout=1">Logout</a>
  19. #
  20. ###############################################################
  21.  
  22. /*
  23. -------------------------------------------------------------------
  24. SAMPLE if you only want to request login and password on login form.
  25. Each row represents different user.
  26.  
  27. $LOGIN_INFORMATION = array(
  28.   'allow' => 'me',
  29.   'dimaslanjaka' => 'xxxx',
  30.   'superuser' => 'MYGJ1kx8CHTlIKq'
  31. );
  32.  
  33. --------------------------------------------------------------------
  34. SAMPLE if you only want to request only password on login form.
  35. Note: only passwords are listed
  36.  
  37. $LOGIN_INFORMATION = array(
  38.   'me',
  39.   'bangsadpo0l',
  40.   'MYGJ1kx8CHTlIKq'
  41. );
  42.  
  43. --------------------------------------------------------------------
  44. */
  45.  
  46. ##################################################################
  47. #  SETTINGS START
  48. ##################################################################
  49.  
  50. // Add login/password pairs below, like described above
  51. // NOTE: all rows except last must have comma "," at the end of line
  52. $LOGIN_INFORMATION = array(
  53.   'allow' => 'me',
  54.   'dimaslanjaka' => 'xxxxx',
  55.   'superuser' => 'MYGJ1kx8CHTlIKq',
  56. );
  57.  
  58. // request login? true - show login and password boxes, false - password box only
  59. define('USE_USERNAME', true);
  60.  
  61. // User will be redirected to this page after logout
  62. define('LOGOUT_URL', '/');
  63.  
  64. // time out after NN minutes of inactivity. Set to 0 to not timeout
  65. define('TIMEOUT_MINUTES', 60);
  66.  
  67. // This parameter is only useful when TIMEOUT_MINUTES is not zero
  68. // true - timeout time from last activity, false - timeout time from login
  69. define('TIMEOUT_CHECK_ACTIVITY', true);
  70.  
  71. ##################################################################
  72. #  SETTINGS END
  73. ##################################################################
  74.  
  75.  
  76. ///////////////////////////////////////////////////////
  77. // do not change code below
  78. ///////////////////////////////////////////////////////
  79.  
  80. // show usage example
  81. if(isset($_GET['help'])) {
  82.   die('Include following code into every page you would like to protect, at the very beginning (first line):<br>&lt;?php include("' . str_replace('\\','\\\\',__FILE__) . '"); ?&gt;');
  83. }
  84.  
  85. // timeout in seconds
  86. $timeout = (TIMEOUT_MINUTES == 0 ? 0 : time() + TIMEOUT_MINUTES * 60);
  87.  
  88. // logout?
  89. if(isset($_GET['logout'])) {
  90.   setcookie("verify", '', $timeout, '/'); // clear password;
  91.   header('Location: ' . LOGOUT_URL);
  92.   exit();
  93. }
  94.  
  95. if(!function_exists('showLoginPasswordProtect')) {
  96.  
  97. // show login form
  98. function showLoginPasswordProtect($error_msg) {
  99. ?>
  100. <html>
  101. <head>
  102.   <title>Restricted Access</title>
  103.   <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
  104.   <META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
  105. <meta content='width=device-width,minimum-scale=1,initial-scale=1' name='viewport'/>
  106. </head>
  107. <body>
  108.   <style>
  109.     input { border: 1px solid black; }
  110.   </style>
  111.   <div style="width:500px; margin-left:auto; margin-right:auto; text-align:center">
  112.   <form method="post">
  113.     <h3>Enter password</h3>
  114.     <font color="red"><?php echo $error_msg; ?></font><br />
  115. <?php if (USE_USERNAME) echo 'Login:<br /><input type="input" name="access_login" /><br />Password:<br />'; ?>
  116.     <input type="password" name="access_password" /><p></p><input type="submit" name="Submit" value="Submit" />
  117.   </form>
  118.   <br />
  119.   <!--a style="font-size:9px; color: #B0B0B0; font-family: Verdana, Arial;" href="http://www.zubrag.com/scripts/password-protect.php" title="Download Password Protector">Powered by Password Protect</a-->
  120.   </div>
  121. </body>
  122. </html>
  123.  
  124. <?php
  125.   // stop at this point
  126.   die();
  127. }
  128. }
  129.  
  130. // user provided password
  131. if (isset($_POST['access_password'])) {
  132.  
  133.   $login = isset($_POST['access_login']) ? $_POST['access_login'] : '';
  134.   $pass = $_POST['access_password'];
  135.   if (!USE_USERNAME && !in_array($pass, $LOGIN_INFORMATION)
  136.   || (USE_USERNAME && ( !array_key_exists($login, $LOGIN_INFORMATION) || $LOGIN_INFORMATION[$login] != $pass ) )
  137.   ) {
  138.     showLoginPasswordProtect("Incorrect password.");
  139.   }
  140.   else {
  141.     // set cookie if password was validated
  142.     setcookie("verify", md5($login.'%'.$pass), $timeout, '/');
  143.    
  144.     // Some programs (like Form1 Bilder) check $_POST array to see if parameters passed
  145.     // So need to clear password protector variables
  146.     unset($_POST['access_login']);
  147.     unset($_POST['access_password']);
  148.     unset($_POST['Submit']);
  149.   }
  150.  
  151. }
  152.  
  153. else {
  154.  
  155.   // check if password cookie is set
  156.   if (!isset($_COOKIE['verify'])) {
  157.     showLoginPasswordProtect("");
  158.   }
  159.  
  160.   // check if cookie is good
  161.   $found = false;
  162.   foreach($LOGIN_INFORMATION as $key=>$val) {
  163.     $lp = (USE_USERNAME ? $key : '') .'%'.$val;
  164.     if ($_COOKIE['verify'] == md5($lp)) {
  165.       $found = true;
  166.       // prolong timeout
  167.       if (TIMEOUT_CHECK_ACTIVITY) {
  168.         setcookie("verify", md5($lp), $timeout, '/');
  169.       }
  170.       break;
  171.     }
  172.   }
  173.   if (!$found) {
  174.     showLoginPasswordProtect("");
  175.   }
  176.  
  177. }
  178.  
  179. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement