|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $length
|
|
|
|
* @return string|false
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
function token($length = 32) {
|
PHP SESSION Prefix and IP check, engine constants and user_constants as a function for better memory usage, add SQLite 3 driver, new loader for aditional database method, new REST HTPP method check, updated template engines: Mustache 2.13, Smarty 3.1.34, Twig 1.42.5, Twig 2.12.5, add Twig 3 support to PHP 7.2+, define Dwoo template as deprecated, Caches and captcha bugfix in PHP 5.4.x
5 years ago
|
|
|
if(!isset($length) || intval($length) <= 8 ){
|
|
|
|
$length = 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (function_exists('openssl_random_pseudo_bytes')) {
|
|
|
|
$token = bin2hex(openssl_random_pseudo_bytes($length));
|
|
|
|
} elseif (function_exists('random_bytes')) {
|
|
|
|
$token = bin2hex(random_bytes($length));
|
|
|
|
} elseif (function_exists('mcrypt_create_iv') && phpversion() < '7.1') {
|
|
|
|
$token = bin2hex(mcrypt_create_iv($length, MCRYPT_DEV_URANDOM));
|
|
|
|
} else {
|
|
|
|
$token = md5(rand(0, 4000).time());
|
|
|
|
}
|
|
|
|
|
|
|
|
return substr($token, -$length, $length);
|
|
|
|
}
|
PHP SESSION Prefix and IP check, engine constants and user_constants as a function for better memory usage, add SQLite 3 driver, new loader for aditional database method, new REST HTPP method check, updated template engines: Mustache 2.13, Smarty 3.1.34, Twig 1.42.5, Twig 2.12.5, add Twig 3 support to PHP 7.2+, define Dwoo template as deprecated, Caches and captcha bugfix in PHP 5.4.x
5 years ago
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|