1<?php
2
3/**
4 * PHP Class for handling Yubi Authenticator 2-factor authentication
5 *
6 * @author Michael Kliewe
7 * @copyright 2012 Michael Kliewe
8 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
9 * @link http://www.phpgangsta.de/
10 */
11
12class PHP_YubiAuthenticator
13{
14    /**
15     * Check if the code is correct. Ask configured API Server.
16     *
17     * @param string $url
18     * @return bool
19     */
20    public function verifyCode($url, &$response)
21    {
22        $curl = curl_init();
23        curl_setopt($curl, CURLOPT_URL, $url);
24        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
25        $result = curl_exec($curl);
26        curl_close($curl);
27
28        $results = explode(PHP_EOL, $result);
29        foreach ($results as $item) {
30            $delpos = strpos($item,'=');
31            if($delpos == false) continue;
32            $response[substr($item,0,$delpos)] = substr($item, $delpos+1);
33        }
34
35        return $response["status"]=="OK";
36    }
37}
38