diff options
Diffstat (limited to 'public/system/helper/general.php')
-rw-r--r-- | public/system/helper/general.php | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/public/system/helper/general.php b/public/system/helper/general.php new file mode 100644 index 0000000..1542810 --- /dev/null +++ b/public/system/helper/general.php @@ -0,0 +1,39 @@ +<?php +function token($length = 32) { + // Create random token + $string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + + $max = strlen($string) - 1; + + $token = ''; + + for ($i = 0; $i < $length; $i++) { + $token .= $string[mt_rand(0, $max)]; + } + + return $token; +} + +/** + * Backwards support for timing safe hash string comparisons + * + * http://php.net/manual/en/function.hash-equals.php + */ + +if(!function_exists('hash_equals')) { + function hash_equals($known_string, $user_string) { + $known_string = (string)$known_string; + $user_string = (string)$user_string; + + if(strlen($known_string) != strlen($user_string)) { + return false; + } else { + $res = $known_string ^ $user_string; + $ret = 0; + + for($i = strlen($res) - 1; $i >= 0; $i--) $ret |= ord($res[$i]); + + return !$ret; + } + } +}
\ No newline at end of file |