move method to create random hashes to Utils-class
This commit is contained in:
parent
60036ea794
commit
bf0d324655
2 changed files with 26 additions and 23 deletions
|
@ -19,6 +19,14 @@
|
|||
*/
|
||||
class Utils
|
||||
{
|
||||
/**
|
||||
* String length for hashes
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const HASH_LENGTH = 10;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
@ -209,6 +217,23 @@
|
|||
return $mimetype;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a random hash string.
|
||||
*
|
||||
* @param int Length of string
|
||||
* @return string String with random characters
|
||||
*/
|
||||
public static function createRandomHash($length=self::HASH_LENGTH)
|
||||
{
|
||||
// Length of URL
|
||||
$length = max(0, min(32, $length));
|
||||
|
||||
|
||||
// Create and return random string
|
||||
return substr(md5(microtime()), rand(0, 32-$length), $length);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue