Guest User

Untitled

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