Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix password generation
Signed-off-by: Vincent Petry <[email protected]>
  • Loading branch information
PVince81 committed May 12, 2022
commit 4ff2fd3fa51b04f916514e246dcddfddbfdb0ca2
15 changes: 13 additions & 2 deletions lib/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ public function __construct(PasswordPolicyConfig $config,
* @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 = '';
Expand Down Expand Up @@ -86,14 +91,20 @@ public function generate(): string {

try {
$this->validator->validate($password);

if ($password === null || $password === '') {
// something went wrong
break;
}

$found = true;
break;
} catch (HintException $e) {
/*
* Invalid so lets go for another round
* Reset the length so we don't run below zero
*/
$lenght = $this->config->getMinLength();
$lenght = $minLength;
}
}

Expand Down