Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
226 | daniel-mar | 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 VolcanoAuthMD5 implements VolcanoAuthProvider { |
||
9 | public static function checkId($id) { |
||
10 | return self::strEqual($id, 'md5', true); // is always case insensitive |
||
11 | } |
||
12 | |||
13 | public static function checkAuth($candidate, $token) { |
||
14 | return md5($token) === $candidate; // TODO salt |
||
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 VolcanoAuthMD5()); |
||
28 | |||
29 | # --- TEST |
||
30 | |||
31 | /* |
||
32 | $x = new VolcanoAuthMD5(); |
||
33 | assert( $x->checkAuth('d41d8cd98f00b204e9800998ecf8427e', '')); |
||
34 | assert( $x->checkAuth('098f6bcd4621d373cade4e832627b4f6', 'test')); |
||
35 | assert(!$x->checkAuth('987bcab01b929eb2c07877b224215c92', 'xyz')); |
||
36 | */ |
||
37 |