fipamo/brain/utility/StringTools.inc.php

42 lines
955 B
PHP
Raw Normal View History

<?php
//include "brain/data/Auth.inc.php";
class StringTools
{
2021-04-14 05:49:12 +02:00
public static function createUUID()
{
if (function_exists("com_create_guid") === true) {
return trim(com_create_guid(), "{}");
}
return sprintf(
"%04X%04X-%04X-%04X-%04X-%04X%04X%04X",
mt_rand(0, 65535),
mt_rand(0, 65535),
mt_rand(0, 65535),
mt_rand(16384, 20479),
mt_rand(32768, 49151),
mt_rand(0, 65535),
mt_rand(0, 65535),
mt_rand(0, 65535)
);
}
public static function randomString(int $length)
{
$alphanum =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
$special = '*&!@%^#$';
$alphabet = $alphanum . $special;
$random = openssl_random_pseudo_bytes($length);
$alphabet_length = strlen($alphabet);
$string = "";
for ($i = 0; $i < $length; ++$i) {
$string .= $alphabet[ord($random[$i]) % $alphabet_length];
}
return $string;
}
}