Completed
Push — master ( 054192...eb3219 )
by Torben
02:56 queued 01:47
created

ChallengeResponseSpamCheck::isFailed()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
declare(strict_types=1);
3
namespace DERHANSEN\SfEventMgt\SpamChecks;
4
5
/*
6
 * This file is part of the Extension "sf_event_mgt" for TYPO3 CMS.
7
 *
8
 * For the full copyright and license information, please read the
9
 * LICENSE.txt file that was distributed with this source code.
10
 */
11
12
use DERHANSEN\SfEventMgt\Utility\MiscUtility;
13
14
/**
15
 * ChallengeResponseSpamCheck
16
 */
17
class ChallengeResponseSpamCheck extends AbstractSpamCheck
18
{
19
    /**
20
     * Checks, if the cr-response field matches the expected ROT13 encrypted/obfuscated string.
21
     *
22
     * @return bool
23
     */
24
    public function isFailed(): bool
25
    {
26
        if (!isset($this->arguments['registration']['cr-response'])) {
27
            return true;
28
        }
29
30
        $challenge =  MiscUtility::getSpamCheckChallenge((int)$this->arguments['event']);
31
        $originalChallenge = $this->configuration['prefix'] . $challenge . $this->configuration['postfix'];
32
33
        $expectedResponse = str_rot13($originalChallenge);
34
        $response = $this->arguments['registration']['cr-response'];
35
36
        return $expectedResponse !== $response;
37
    }
38
}
39