Tiqr_OcraService_Tiqr   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 62.5%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
c 2
b 0
f 0
dl 0
loc 23
ccs 5
cts 8
cp 0.625
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A verifyResponse() 0 17 3
1
<?php
2
3
/**
4
 * This file is part of the tiqr project.
5
 *
6
 * The tiqr project aims to provide an open implementation for
7
 * authentication using mobile devices. It was initiated by
8
 * SURFnet and developed by Egeniq.
9
 *
10
 * More information: http://www.tiqr.org
11
 *
12
 * @author Ivo Jansch <[email protected]>
13
 *
14
 * @package tiqr
15
 *
16
 * @license New BSD License - See LICENSE file for details.
17
 *
18
 * @copyright (C) 2010-2012 SURFnet BV
19
 */
20
21
/**
22
 * The implementation for the tiqr ocra service class.
23
 *
24
 * @author lineke
25
 *
26
 */
27
class Tiqr_OcraService_Tiqr extends Tiqr_OcraService_Abstract
28
{
29
30
    /**
31
     *  @see Tiqr_OcraService_Interface::verifyResponse()
32
     */
33 4
    public function verifyResponse(String $response, String $userId, String $userSecret, String $challenge, String $sessionInformation): bool
34
    {
35
        // Calculate the response. Because we have the same information as the client this should result in the same
36
        // response as the client calculated.
37
        try {
38 4
            $expected = OCRA::generateOCRA($this->_ocraSuite, $userSecret, "", $challenge, "", $sessionInformation, "");
39
        }
40
        catch (Exception $e) {
41
            $this->logger->warning(sprintf('Error calculating OCRA response for user "%s"', $userId), array('exception'=>$e));
42
            return false;
43
        }
44
45 4
        if (strlen($expected) != strlen($response)) {
46 2
            $this->logger->warning('verifyResponse: calculated and expected response have different lengths');
47
        }
48
        // Use constant time compare
49 4
        return $this->_ocraParser->constEqual($expected, $response);
50
    }
51
}
52