parent
e31dda35df
commit
a8aa6d1939
2 changed files with 27 additions and 10 deletions
|
@ -6,7 +6,8 @@ import anunidecode
|
|||
INVALID_PASSWORD_MESSAGE = 'Invalid password, password must be at least ' + \
|
||||
'8 characters and contain no whitespace.'
|
||||
INVALID_USERNAME_CHARACTERS = r'[^a-z0-9_]'
|
||||
VALID_CHARACTERS = '_' + string.digits + string.lowercase
|
||||
VALID_CHARACTERS = string.digits + string.lowercase
|
||||
|
||||
MIN_LENGTH = 4
|
||||
MAX_LENGTH = 30
|
||||
|
||||
|
@ -48,8 +49,13 @@ def _gen_filler_chars(num_filler_chars):
|
|||
|
||||
|
||||
def generate_valid_usernames(input_username):
|
||||
# Docker's regex: [a-z0-9]+(?:[._-][a-z0-9]+)*
|
||||
normalized = input_username.encode('unidecode', 'ignore').strip().lower()
|
||||
prefix = re.sub(INVALID_USERNAME_CHARACTERS, '_', normalized)[:30]
|
||||
prefix = re.sub(r'_{2,}', '_', prefix)
|
||||
|
||||
if prefix.endswith('_'):
|
||||
prefix = prefix[0:len(prefix) - 1]
|
||||
|
||||
num_filler_chars = max(0, MIN_LENGTH - len(prefix))
|
||||
|
||||
|
|
Reference in a new issue