You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To resolve the error, you can automatically increase the password length if it is less than the number of required categories, setting it at least equal to the number of required categories. Subsequently, the characters are completed with random ones from the available pool, still respecting the categories, and finally they are mixed to avoid predictable patterns. For example:
# If the required tokens exceed the requested length, adjust the length to be at least the number of required categoriesiflen(required_tokens) >length:
length=len(required_tokens)
# Create the password starting with the mandatory required tokenschars=required_tokens# Add random characters from the available pool until the password reaches the requested lengthwhilelen(chars) <length:
chars.append(self.generator.random.choice(available_tokens))
# Shuffle the characters to avoid predictable patterns and ensure randomnessrandom.shuffle(chars)
# Return the password as a string, truncated to the desired lengthreturn''.join(chars[:length])
I got
AssertionError: Required length is shorter than required characters
when using Faker().password(length = 2)the error occurs when the input length is less than the character pool.
here is the current code
https://github.com/joke2k/faker/blob/master/faker/providers/misc/__init__.py#L144
maybe need to separate the required token and the available token for the input?
The text was updated successfully, but these errors were encountered: