Completed
Push — master ( e332d4...504537 )
by Torben
02:37
created

OldPasswordService::getFrontendUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
namespace Derhansen\FeChangePwd\Service;
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
use TYPO3\CMS\Core\Utility\GeneralUtility;
13
use TYPO3\CMS\Core\Crypto\PasswordHashing\PasswordHashFactory;
14
use TYPO3\CMS\Saltedpasswords\Salt\SaltFactory;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Saltedpasswords\Salt\SaltFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use TYPO3\CMS\Saltedpasswords\Utility\SaltedPasswordsUtility;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Saltedpassword...\SaltedPasswordsUtility was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
17
/**
18
 * Class OldPasswordsService
19
 */
20
class OldPasswordService
21
{
22
    /**
23
     * Returns if the given password equals the old password
24
     *
25
     * @param string $password
26
     * @return bool
27
     * @throws MissingPasswordHashServiceException
28
     * @throws \TYPO3\CMS\Core\Crypto\PasswordHashing\InvalidPasswordHashException
29
     */
30
    public function checkNewEqualsOldPassword(string $password)
31
    {
32
        if (class_exists(PasswordHashFactory::class)) {
33
            $hashInstance = GeneralUtility::makeInstance(PasswordHashFactory::class)->getDefaultHashInstance('FE');
34
            $equals = $hashInstance->checkPassword($password, $this->getFrontendUser()->user['password']);
35
        } elseif (SaltedPasswordsUtility::isUsageEnabled('FE')) {
36
            $saltingInstance = SaltFactory::getSaltingInstance();
37
            $equals = $saltingInstance->checkPassword($password, $this->getFrontendUser()->user['password']);
38
        } else {
39
            throw new MissingPasswordHashServiceException(
40
                'No secure password hashing service could be initialized. Please check your TYPO3 system configuration',
41
                1557550040515
42
            );
43
        }
44
45
        return $equals;
46
    }
47
48
    /**
49
     * Returns the frontendUserAuthentication
50
     *
51
     * @return \TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication
52
     */
53
    protected function getFrontendUser()
54
    {
55
        return $GLOBALS['TSFE']->fe_user;
56
    }
57
}
58