src/Password/StrengthValidator/PasswordStrengthValidator.php
public function generateValid($length, PasswordPolicyInterface $policy)
    {
        if ($length < 16) {
            throw new LogicException('Minimal password length that this utility can generate is 16 characters');
        }

        if ($length < $policy->getMinLength()) {
            throw new LogicException('Password policy requires longer password');
        }

        $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';

        if ($policy->requireSymbols()) {
            $characters .= ',.;:!$%^&';
        }

        $counter = 0;

        while (++$counter < 10000) {
            try {
                $password = $this->generateRandomString($length, $characters);

                if ($this->validate($password, $policy)) {
                    return $password;
                }
            } catch (InvalidPasswordException $e) {
            }
        }

        throw new RuntimeException('Failed to generate new password in 1000 iterations');
    }
public function generateValid($length, PasswordPolicyInterface $policy)
    {
        if ($length < 16) {
            throw new LogicException('Minimal password length that this utility can generate is 16 characters');
        }

        if ($length < $policy->getMinLength()) {
            throw new LogicException('Password policy requires longer password');
        }

        $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';

        if ($policy->requireSymbols()) {
            $characters .= ',.;:!$%^&';
        }

        $counter = 0;

        while (++$counter < 10000) {
            try {
                $password = $this->generateRandomString($length, $characters);

                if ($this->validate($password, $policy)) {
                    return $password;
                }
            } catch (InvalidPasswordException $e) {
            }
        }

        throw new RuntimeException('Failed to generate new password in 1000 iterations');
    }
{@inheritdoc}