This repository has been archived by the owner on Oct 31, 2020. It is now read-only.
/
secure.php
78 lines (70 loc) · 1.49 KB
/
secure.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
<?php
// Validate an email address
//
// @param string $mail
//
// @return bool false if address is not a real one
function validMail($mail) {
if (!filter_var($mail, FILTER_VALIDATE_EMAIL)) {
return false;
} else {
return true;
}
}
// validate a path
//
// @param string $path
//
// @return bool false if path is not a real one
function validPath($path) {
if (!filter_var($path, FILTER_VALIDATE_URL)) {
return false;
} else {
return true;
}
}
// secures an array with htmlspecialchars()
//
// @param array $dataArray
//
// @return array secured array
function secureArray($dataArray) {
$secureArray = array();
foreach ($dataArray as $key => $val) {
$key = secureString((string) $key);
if (is_string($val)) {
$val = secureString($val);
}
$secureArray[$key] = $val;
}
return $secureArray;
}
// secures a string with htmlspecialchars()
//
// @param string $string
//
// @return string secured string
function secureString($string) {
return htmlspecialchars($string, ENT_QUOTES);
}
// hash a password with given salt
//
// @param string $password
// @param string $salt
//
// @return string hash value
function hashPassword($password, $salt) {
return hash_hmac('md5', $password, $salt);
}
// check whether a string is empty
//
// @param string $string
//
// @return bool true if string is empty
function isStringEmpty($string) {
if (str_replace(' ', '', $string) == '') {
return true;
}
return false;
}
?>