Passed
Push — master ( a24d5d...5d2fe9 )
by Julien
05:02
created

Security::hash()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
c 1
b 0
f 1
dl 0
loc 13
ccs 0
cts 10
cp 0
rs 10
cc 2
nc 2
nop 2
crap 6
1
<?php
2
3
/**
4
 * This file is part of the Zemit Framework.
5
 *
6
 * (c) Zemit Team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zemit\Encryption;
13
14
use Phalcon\Encryption\Security as PhalconSecurity;
15
use Zemit\Config\ConfigInterface;
16
17
/**
18
 * {@inheritDoc}
19
 */
20
class Security extends PhalconSecurity
21
{
22
    public function getConfig(): ConfigInterface
23
    {
24
        return $this->getDI()->get('config');
25
    }
26
    
27
    public function hash(string $password, array $options = []) : string
28
    {
29
        if (in_array($this->getDefaultHash(), [
30
            PhalconSecurity::CRYPT_ARGON2I,
31
            PhalconSecurity::CRYPT_ARGON2ID
32
        ])) {
33
            $defaultOptions = $this->getConfig()->pathToArray('security.argon2');
34
            $options['memory_cost'] ??= $defaultOptions['memoryCost'];
35
            $options['time_cost'] ??= $defaultOptions['timeCost'];
36
            $options['threads'] ??= $defaultOptions['threads'];
37
        }
38
        
39
        return parent::hash($password, $options);
40
    }
41
}
42