in marketplace/deployer_util/password.py [0:0]
def GeneratePassword(length=8, include_symbols=False):
"""Generates a random password."""
if length < MIN_LENGTH:
raise InputError('Password length must be at least %d' % MIN_LENGTH)
candidates = (
CANDIDATES_WITH_SYMBOLS
if include_symbols else CANDIDATES_WITHOUT_SYMBOLS)
categories = (
CATEGORIES_WITH_SYMBOLS
if include_symbols else CATEGORIES_WITHOUT_SYMBOLS)
# Generates up to the specified length minus the number of categories.
# Then inserts one character for each category, ensuring that the character
# satisfy the category if the generated string hasn't already.
generated = (
[random.choice(ALPHABET)] +
[random.choice(candidates) for _ in range(length - 1 - len(categories))])
for category in categories:
_InsertAndEnsureSatisfaction(generated, category, candidates)
return ''.join(generated)