mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-05-14 05:31:42 +00:00
add new function uniqidReal()
This commit is contained in:
parent
f6ec37df74
commit
68427394ae
|
@ -683,7 +683,7 @@ function addDirSep($str) { /* {{{ */
|
||||||
* @param string $command The command to check
|
* @param string $command The command to check
|
||||||
* @return bool True if the command has been found ; otherwise, false.
|
* @return bool True if the command has been found ; otherwise, false.
|
||||||
*/
|
*/
|
||||||
function commandExists ($command) {
|
function commandExists ($command) { /* {{{ */
|
||||||
$whereIsCommand = (PHP_OS == 'WINNT') ? 'where' : 'command -v';
|
$whereIsCommand = (PHP_OS == 'WINNT') ? 'where' : 'command -v';
|
||||||
|
|
||||||
$process = proc_open(
|
$process = proc_open(
|
||||||
|
@ -706,7 +706,7 @@ function commandExists ($command) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
} /* }}} */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a file from disk to the browser
|
* Send a file from disk to the browser
|
||||||
|
@ -855,6 +855,23 @@ function createNonce() { /* {{{ */
|
||||||
return base64_encode($bytes);
|
return base64_encode($bytes);
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a real uniqid for cryptographic purposes
|
||||||
|
*
|
||||||
|
* @ return string
|
||||||
|
*/
|
||||||
|
function uniqidReal($lenght = 13) {
|
||||||
|
// uniqid gives 13 chars, but you could adjust it to your needs.
|
||||||
|
if (function_exists("random_bytes")) {
|
||||||
|
$bytes = random_bytes(ceil($lenght / 2));
|
||||||
|
} elseif (function_exists("openssl_random_pseudo_bytes")) {
|
||||||
|
$bytes = openssl_random_pseudo_bytes(ceil($lenght / 2));
|
||||||
|
} else {
|
||||||
|
throw new Exception("no cryptographically secure random function available");
|
||||||
|
}
|
||||||
|
return substr(bin2hex($bytes), 0, $lenght);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare function for sorting users by login
|
* Compare function for sorting users by login
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue
Block a user