| Conditions | 3 |
| Paths | 3 |
| Total Lines | 13 |
| Code Lines | 7 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 22 | public static function generate( |
||
| 23 | $length = 8, |
||
| 24 | $keyspace = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%' |
||
| 25 | ) { |
||
| 26 | $str = ''; |
||
| 27 | $max = mb_strlen($keyspace, '8bit') - 1; |
||
| 28 | if ($max < 1) { |
||
| 29 | throw new Exception('$keyspace must be at least two characters long'); |
||
|
|
|||
| 30 | } |
||
| 31 | for ($i = 0; $i < $length; ++$i) { |
||
| 32 | $str .= $keyspace[random_int(0, $max)]; |
||
| 33 | } |
||
| 34 | return $str; |
||
| 35 | } |
||
| 38 |