-
Notifications
You must be signed in to change notification settings - Fork 10
/
helpers.php
95 lines (81 loc) · 1.81 KB
/
helpers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
class Helpers{
function __construct($_GeniSys)
{
$this->_GeniSys = $_GeniSys;
}
public function decrypt($value)
{
list($iv, $value) = explode(
'@@',
base64_decode($value));
return mcrypt_decrypt(
MCRYPT_RIJNDAEL_256,
$this->_GeniSys->_key,
$value,
MCRYPT_MODE_CFB,
$iv);
}
public function encrypt($value)
{
$iv = mcrypt_create_iv(
mcrypt_get_iv_size(
MCRYPT_RIJNDAEL_256,
MCRYPT_MODE_CFB),
MCRYPT_RAND);
return base64_encode(
$iv . '@@' . mcrypt_encrypt(
MCRYPT_RIJNDAEL_256,
$this->_GeniSys->_key,
$value,
MCRYPT_MODE_CFB,
$iv));
}
public function decryptString($string)
{
return $this->decrypt($string);
}
public function getUserIP()
{
if(array_key_exists(
'HTTP_X_FORWARDED_FOR',
$_SERVER) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])):
if (strpos(
$_SERVER['HTTP_X_FORWARDED_FOR'],
',') > 0):
$addr = explode(
",",
$_SERVER['HTTP_X_FORWARDED_FOR']);
return trim($addr[0]);
else:
return $_SERVER['HTTP_X_FORWARDED_FOR'];
endif;
else:
return $_SERVER['REMOTE_ADDR'];
endif;
}
public static function verifyPassword($password, $hash)
{
return password_verify(
$password,
$hash);
}
public static function createPasswordHash($password)
{
return password_hash(
$password,
PASSWORD_DEFAULT);
}
public function createHMAC($params=[], $secret)
{
$parameters = null;
foreach($params AS $paramsKey => $paramsValue):
$parameters = $parameters . $paramsValue . ".";
endforeach;
return hash_hmac("sha256",
rtrim(
$parameters,
"."),
$secret);
}
}