accounts/common/components/UserFriendlyRandomKey.php

20 lines
399 B
PHP
Raw Normal View History

<?php
2018-04-18 02:17:25 +05:30
declare(strict_types=1);
2018-04-18 02:17:25 +05:30
namespace common\components;
class UserFriendlyRandomKey {
2018-04-18 02:17:25 +05:30
public static function make(int $length = 18) {
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
$numChars = strlen($chars);
$key = '';
for ($i = 0; $i < $length; $i++) {
$key .= $chars[random_int(0, $numChars - 1)];
}
return $key;
}
}