mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-21 13:54:02 -07:00
Merge pull request #575 from torrentpier/simplified-make_rand_str-function
Simplified make_rand_str function
This commit is contained in:
commit
48066b7baa
1 changed files with 12 additions and 6 deletions
18
common.php
18
common.php
|
@ -349,13 +349,19 @@ function str_compact($str)
|
||||||
return preg_replace('#\s+#u', ' ', trim($str));
|
return preg_replace('#\s+#u', ' ', trim($str));
|
||||||
}
|
}
|
||||||
|
|
||||||
function make_rand_str($len = 10)
|
/**
|
||||||
|
* Generate a "random" alphanumeric string.
|
||||||
|
*
|
||||||
|
* Should not be considered sufficient for cryptography, etc.
|
||||||
|
*
|
||||||
|
* @param int|string $length
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function make_rand_str($length = 10): string
|
||||||
{
|
{
|
||||||
$str = '';
|
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||||
while (strlen($str) < $len) {
|
|
||||||
$str .= str_shuffle(preg_replace('#[^0-9a-zA-Z]#', '', password_hash(uniqid(mt_rand(), true), PASSWORD_BCRYPT)));
|
return substr(str_shuffle(str_repeat($pool, (int)$length)), 0, $length);
|
||||||
}
|
|
||||||
return substr($str, 0, $len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function array_deep(&$var, $fn, $one_dimensional = false, $array_only = false)
|
function array_deep(&$var, $fn, $one_dimensional = false, $array_only = false)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue