2016-01-15 12:21:27 +03:00
|
|
|
<?php
|
2018-04-17 23:47:25 +03:00
|
|
|
declare(strict_types=1);
|
2016-01-15 12:21:27 +03:00
|
|
|
|
2018-04-17 23:47:25 +03:00
|
|
|
namespace common\components;
|
2016-01-15 12:21:27 +03:00
|
|
|
|
|
|
|
class UserFriendlyRandomKey {
|
|
|
|
|
2018-04-17 23:47:25 +03:00
|
|
|
public static function make(int $length = 18) {
|
2016-01-15 12:21:27 +03:00
|
|
|
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
|
|
|
|
$numChars = strlen($chars);
|
|
|
|
$key = '';
|
|
|
|
for ($i = 0; $i < $length; $i++) {
|
2016-11-01 19:36:39 +03:00
|
|
|
$key .= $chars[random_int(0, $numChars - 1)];
|
2016-01-15 12:21:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return $key;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|