diff options
author | Vincent Petry <vincent@nextcloud.com> | 2022-05-12 13:37:15 +0300 |
---|---|---|
committer | backportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com> | 2022-05-12 15:05:23 +0300 |
commit | 447f5daf6f304c1478e4ed4415f6a7ef0e5578df (patch) | |
tree | 6879360bc5bfe9690a1567ba636fc618861a45b6 | |
parent | 7080f52ff9c2cb8d3927bfcfa08abcd20a01ead3 (diff) |
Fix password generation
Signed-off-by: Vincent Petry <vincent@nextcloud.com>
-rw-r--r-- | lib/Generator.php | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/Generator.php b/lib/Generator.php index 1328054..60aa54f 100644 --- a/lib/Generator.php +++ b/lib/Generator.php @@ -52,7 +52,12 @@ class Generator { * @throws HintException */ public function generate(): string { - $lenght = $this->config->getMinLength(); + $minLength = $this->config->getMinLength(); + if ($minLength < 8) { + // 8 minimum so we don't generate too short passwords + $minLength = 8; + } + $lenght = $minLength; $password = ''; $chars = ''; @@ -86,6 +91,12 @@ class Generator { try { $this->validator->validate($password); + + if ($password === null || $password === '') { + // something went wrong + break; + } + $found = true; break; } catch (HintException $e) { @@ -93,7 +104,7 @@ class Generator { * Invalid so lets go for another round * Reset the length so we don't run below zero */ - $lenght = $this->config->getMinLength(); + $lenght = $minLength; } } |