|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
if (!function_exists('getPool')) { |
|
4
|
|
|
function getPool($type = 'distinct') |
|
5
|
|
|
{ |
|
6
|
|
|
switch ($type) { |
|
7
|
|
|
case 'alnum': |
|
8
|
|
|
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
|
9
|
|
|
break; |
|
10
|
|
|
case 'alpha': |
|
11
|
|
|
$pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
|
12
|
|
|
break; |
|
13
|
|
|
case 'hexdec': |
|
14
|
|
|
$pool = '0123456789abcdef'; |
|
15
|
|
|
break; |
|
16
|
|
|
case 'numeric': |
|
17
|
|
|
$pool = '0123456789'; |
|
18
|
|
|
break; |
|
19
|
|
|
case 'nozero': |
|
20
|
|
|
$pool = '123456789'; |
|
21
|
|
|
break; |
|
22
|
|
|
case 'distinct': |
|
23
|
|
|
$pool = '2345679ACDEFHJKLMNPRSTUVWXYZ'; |
|
24
|
|
|
break; |
|
25
|
|
|
default: |
|
26
|
|
|
$pool = (string) $type; |
|
27
|
|
|
break; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
return $pool; |
|
31
|
|
|
} |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
if (!function_exists('secureCrypt')) { |
|
35
|
|
|
function secureCrypt($min, $max) |
|
36
|
|
|
{ |
|
37
|
|
|
$range = $max - $min; |
|
38
|
|
|
|
|
39
|
|
|
if ($range < 0) { |
|
40
|
|
|
return $min; // not so random... |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$log = log($range, 2); |
|
44
|
|
|
$bytes = (int) ($log / 8) + 1; // length in bytes |
|
45
|
|
|
$bits = (int) $log + 1; // length in bits |
|
46
|
|
|
$filter = (int) (1 << $bits) - 1; // set all lower bits to 1 |
|
47
|
|
|
do { |
|
48
|
|
|
$rnd = hexdec(bin2hex(openssl_random_pseudo_bytes($bytes))); |
|
49
|
|
|
$rnd = $rnd & $filter; // discard irrelevant bits |
|
50
|
|
|
} while ($rnd >= $range); |
|
51
|
|
|
|
|
52
|
|
|
return $min + $rnd; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
if (!function_exists('getHashedToken')) { |
|
57
|
|
|
function getHashedToken($length = 25) |
|
58
|
|
|
{ |
|
59
|
|
|
$token = ''; |
|
60
|
|
|
$max = strlen(getPool()); |
|
61
|
|
|
for ($i = 0; $i < $length; $i++) { |
|
62
|
|
|
$token .= getPool()[ secureCrypt(0, $max) ]; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return $token; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
if (!function_exists('createHash')) { |
|
70
|
|
|
function createHash($apiKey, $body) |
|
71
|
|
|
{ |
|
72
|
|
|
$hash = ''; |
|
73
|
|
|
foreach ($body as $key => $val) { |
|
74
|
|
|
$hash .= $val; |
|
75
|
|
|
} |
|
76
|
|
|
$hash = $hash.$apiKey; |
|
77
|
|
|
$hash = hash('sha512', $hash); |
|
78
|
|
|
|
|
79
|
|
|
return $hash; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
if (!function_exists('paga')) { |
|
84
|
|
|
function paga() |
|
85
|
|
|
{ |
|
86
|
|
|
return app()->make('paga'); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|