Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.33 KB | None | 0 0
  1. <?php
  2.     $validUsers = array(
  3.         'Eckostylez' => array(
  4.             'passWord' => 'urpassword',
  5.             'characters' => array('CharName1', 'CharName2'),
  6.         ),
  7.         'Vortex' => array(
  8.             'passWord' => 'urpassword',
  9.             'characters' => array('CharName1', 'CharName2'),
  10.         ),
  11.     );
  12.    
  13.    
  14.     $userName = trim(arrayGet($_GET, 'un', ''));
  15.     $passWord = trim(arrayGet($_GET, 'pw', ''));
  16.     $character = trim(rrayGet($_GET, 'char', ''));
  17.    
  18.     if(0 == strlen($userName)){
  19.         authError('Username not set');
  20.     }else if(0 == strlen($passWord)){
  21.         authError('Password not set');
  22.     }else if(0 == strlen($character)){
  23.         authError('Character not set');
  24.     }
  25.    
  26.     $user = null;
  27.    
  28.     foreach($validUsers as $uName => $uData){
  29.         if(md5($uName) === $userName){
  30.             //found username
  31.             if(md5($uData['passWord']) !== $passWord){
  32.                 //invalid password
  33.                 authError('Invalid username/password');
  34.             }
  35.             foreach($uData['characters'] as $char){
  36.                 if(md5($char) === $character){
  37.                     die('success');
  38.                 }
  39.             }
  40.             break; // we found the username, nothing matched, so we just break out of the loop
  41.         }
  42.     }
  43.     authError('Invalid username/password');
  44.    
  45.    
  46.    
  47.     //Functions:
  48.    
  49.     function authError($errMsg){
  50.         die('failed'."\n".$errMsg);
  51.     }
  52.    
  53.     function arrayGet(&$arr, $key, $defaultVal){
  54.         if(array_key_exists($key, $arr)){
  55.             return $arr[$key];
  56.         }
  57.         return $defaultVal;
  58.     }
  59. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement