Security   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generateRSAKey() 0 13 3
A createSecureRSAKey() 0 14 4
1
<?php
2
/**
3
 * KumbiaPHP web & app Framework
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject to the new BSD license that is bundled
8
 * with this package in the file LICENSE.
9
 *
10
 * @category   Kumbia
11
 * @package    Security
12
 *
13
 * @copyright  Copyright (c) 2005 - 2019 KumbiaPHP Team (http://www.kumbiaphp.com)
14
 * @license    https://github.com/KumbiaPHP/KumbiaPHP/blob/master/LICENSE   New BSD License
15
 */
16
17
/**
18
 * Clase que contiene métodos útiles para manejar seguridad.
19
 *
20
 * @category   Kumbia
21
 * @package    Security
22
 */
23
abstract class Security
24
{
25
    public static function generateRSAKey($kumbia)
26
    {
27
        $h = date('G') > 12 ? 1 : 0;
28
        $time = uniqid().mktime($h, 0, 0, date('m'), date('d'), date('Y'));
29
        $key = sha1($time);
30
        $_SESSION['rsa_key'] = $key;
31
        $xCode = "<input type='hidden' id='rsa32_key' value='$key' />\r\n";
32
        if ($kumbia) {
33
            echo $xCode;
34
        } else {
35
            return $xCode;
36
        }
37
    }
38
39
    public static function createSecureRSAKey($kumbia = true)
40
    {
41
        $config = Config::read('config');
42
        if ($config->kumbia->secure_ajax) {
43
            if ($_SESSION['rsa_key']) {
44
                if ((time() % 8) == 0) {
45
                    return self::generateRSAKey($kumbia);
46
                }
47
                echo "<input type='hidden' id='rsa32_key' value=\"{$_SESSION['rsa_key']}\"/>";
48
            }
49
50
            return self::generateRSAKey($kumbia);
51
        }
52
    }
53
}
54