OldPasswordService   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 11
c 1
b 0
f 0
dl 0
loc 26
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A checkEqualsOldPassword() 0 16 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Extension "fe_change_pwd" 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
namespace Derhansen\FeChangePwd\Service;
13
14
use Derhansen\FeChangePwd\Exception\MissingPasswordHashServiceException;
15
use TYPO3\CMS\Core\Crypto\PasswordHashing\PasswordHashFactory;
16
use TYPO3\CMS\Core\Utility\GeneralUtility;
17
18
/**
19
 * Class OldPasswordsService
20
 */
21
class OldPasswordService
22
{
23
    /**
24
     * Returns if the given $passwordToCheck is equals the old password by using the given current password hash
25
     *
26
     * @param string $passwordToCheck
27
     * @param string $oldPasswordHash
28
     * @return bool
29
     * @throws MissingPasswordHashServiceException
30
     */
31
    public function checkEqualsOldPassword(string $passwordToCheck, string $oldPasswordHash): bool
32
    {
33
        if (class_exists(PasswordHashFactory::class)) {
34
            $hashInstance = GeneralUtility::makeInstance(PasswordHashFactory::class)->getDefaultHashInstance('FE');
35
            $equals = $hashInstance->checkPassword(
36
                $passwordToCheck,
37
                $oldPasswordHash
38
            );
39
        } else {
40
            throw new MissingPasswordHashServiceException(
41
                'No secure password hashing service could be initialized. Please check your TYPO3 system configuration',
42
                1557550040
43
            );
44
        }
45
46
        return $equals;
47
    }
48
}
49