| Conditions | 3 |
| Paths | 4 |
| Total Lines | 20 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 10 |
| CRAP Score | 3.0067 |
| Changes | 0 | ||
| 1 | <?php |
||
| 29 | 8 | public static function generate_password(int $length = 8, bool $no_similars = true) : string |
|
| 30 | { |
||
| 31 | // Safety |
||
| 32 | 8 | if ($length < 3) { |
|
| 33 | 6 | $length = 8; |
|
| 34 | } |
||
| 35 | |||
| 36 | // Valid characters for default password (PONDER: make configurable ?) |
||
| 37 | 8 | if ($no_similars) { |
|
| 38 | 8 | $first_last_chars = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789'; |
|
| 39 | } else { |
||
| 40 | $first_last_chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; |
||
| 41 | } |
||
| 42 | 8 | $passwdchars = $first_last_chars . '.,-*!:+=()/&%$<>?#@'; |
|
| 43 | |||
| 44 | //make sure password doesn't begin or end in punctuation character |
||
| 45 | 8 | $password = midcom_helper_misc::random_string(1, $first_last_chars); |
|
| 46 | 8 | $password .= midcom_helper_misc::random_string($length - 2, $passwdchars); |
|
| 47 | 8 | $password .= midcom_helper_misc::random_string(1, $first_last_chars); |
|
| 48 | 8 | return $password; |
|
| 49 | } |
||
| 51 |