Authentication.php 825 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. class Authentication {
  3. public static function showPromptIfNeeded() {
  4. if(Configuration::getConfig('authentication', 'enable') === true) {
  5. if(!Authentication::verifyPrompt()) {
  6. header('WWW-Authenticate: Basic realm="RSS-Bridge"');
  7. header('HTTP/1.0 401 Unauthorized');
  8. die('Please authenticate in order to access this instance !');
  9. }
  10. }
  11. }
  12. public static function verifyPrompt() {
  13. if(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
  14. if(Configuration::getConfig('authentication', 'username') === $_SERVER['PHP_AUTH_USER']
  15. && Configuration::getConfig('authentication', 'password') === $_SERVER['PHP_AUTH_PW']) {
  16. return true;
  17. } else {
  18. error_log('[RSS-Bridge] Failed authentication attempt from ' . $_SERVER['REMOTE_ADDR']);
  19. }
  20. }
  21. return false;
  22. }
  23. }