Subversion Repositories oidplus

Rev

Blame | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. # if (!interface_exists('VolcanoAuthProvider')) throw new Exception('Required interface "VolcanoAuthProvider" not found.');
  4. # if (!class_exists('VolcanoDB')) throw new Exception('Required class "VolcanoDB" not found.');
  5.  
  6. require_once __DIR__ . '/../../core/VolcanoAuthProvider.class.php';
  7.  
  8. class VolcanoAuthPlain implements VolcanoAuthProvider {
  9.         public static function checkId($id) {
  10.                 return self::strEqual($id, 'plain', true); // is always case insensitive
  11.         }
  12.  
  13.         public static function checkAuth($candidate, $token) {
  14.                 return $token === $candidate; // TODO case?
  15.         }
  16.  
  17.         protected static function strEqual($str1, $str2, $caseInsensitive = false) {
  18.                 if ($caseInsensitive) {
  19.                         return strtolower($str1) == strtolower($str2);
  20.                 } else {
  21.                         return $str1 == $str2;
  22.                 }
  23.         }
  24. }
  25.  
  26. require_once __DIR__ . '/../../core/1_VolcanoDB.class.php';
  27. VolcanoDB::registerAuthProvider(new VolcanoAuthPlain());
  28.  
  29. # --- TEST
  30.  
  31. /*
  32. $x = new VolcanoAuthPlain();
  33. assert( $x->checkAuth('',     ''));
  34. assert( $x->checkAuth('test', 'test'));
  35. assert(!$x->checkAuth('beta', 'xyz'));
  36. */
  37.  
  38.