Total Complexity | 3 |
Total Lines | 37 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
14 | class Helper |
||
15 | { |
||
16 | /** |
||
17 | * Generate a more truly "random" alpha-numeric string. |
||
18 | * |
||
19 | * @param int $length how long char will generate |
||
20 | * @return string |
||
21 | * @throws \Exception; |
||
22 | */ |
||
23 | public static function random($length = 16) |
||
24 | { |
||
25 | $string = ''; |
||
26 | |||
27 | while (($len = strlen($string)) < $length) { |
||
28 | $size = $length - $len; |
||
29 | |||
30 | $bytes = random_bytes($size); |
||
31 | |||
32 | $string .= substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size); |
||
33 | } |
||
34 | |||
35 | return $string; |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * Generate ISO8601 Time. |
||
40 | * |
||
41 | * @param int $minutes Add Minutes from now |
||
42 | * @return string |
||
43 | */ |
||
44 | public static function generateExpired($minutes = 60) |
||
51 | } |
||
52 | } |
||
53 |