Advertisement
Guest User

Untitled

a guest
Jul 29th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.20 KB | None | 0 0
  1. <?php
  2.     $validUsers = array(
  3.         'Ecko' => 'password',
  4.         'nade' => 'password',
  5.     );
  6.    
  7.     $userName = trim(arrayGet($_GET, 'un', ''));
  8.     $passWord = trim(arrayGet($_GET, 'pw', ''));
  9.     /*
  10.     $ip = $_SERVER["REMOTE_ADDR"];
  11.     $file = "authlogs.txt";
  12.     $logs = fopen($file, 'w');
  13.         fwrite($logs, $userName);
  14.         fwrite($logs, " - ");
  15.         fwrite($logs, $ip);
  16.         fwrite($logs, "\n\n");
  17.         fclose($logs); */
  18.        
  19.     if(0 == strlen($userName)){
  20.         authError('Username not set');
  21.     }else if(0 == strlen($passWord)){
  22.         authError('Password not set');
  23.     }
  24.     $user = null;
  25.    
  26.     foreach($validUsers as $uName => $pWord){
  27.         if(md5($uName) === $userName && md5($pWord) === $passWord){
  28.             die('success');
  29.         }
  30.     }
  31.     authError('Invalid username/password');
  32.    
  33.     //Functions:
  34.    
  35.     function authError($errMsg, $un = null, $pw = null){
  36.         echo('Authorization failed'."\n<br/>".$errMsg);
  37.         echo('<br/><br/>');
  38.         if($un !== null){
  39.             echo('Un: '. $un);
  40.         }
  41.         echo('<br/><br/>');
  42.         if($pw !== null){
  43.             echo('Pw: '. $pw);
  44.         }
  45.         echo('<br/><br/><pre>'.print_r($validUsers, true).'</pre>');
  46.         exit;
  47.     }
  48.    
  49.     function arrayGet(&$arr, $key, $defaultVal){
  50.         if(array_key_exists($key, $arr)){
  51.             return $arr[$key];
  52.         }
  53.         return $defaultVal;
  54.     }
  55. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement