From 570a64f450e01d04a14722900439c509d6d506f7 Mon Sep 17 00:00:00 2001 From: raphael Date: Sun, 16 Jan 2022 13:41:04 +0100 Subject: [PATCH] improves random word generation - only words matching a-zA-Z are used, which removes some situations where the generated code was not readable by the android application - words are now under 10 characters long - function flow improved for readability --- bump/bump.py | 13 +++++++++---- setup.py | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bump/bump.py b/bump/bump.py index b13b7b2..b880746 100644 --- a/bump/bump.py +++ b/bump/bump.py @@ -76,12 +76,17 @@ class Bump: return secrets def generate_secret(self, secrets_file): + pattern = re.compile('^[a-zA-Z]+$') WORDS = r.get_random_words() secret = "" - for _ in range(SENDER_LENGTH + PASSWORD_LENGTH): - secret += random.choice(WORDS) + "-" - while len(secret[SENDER_LENGTH:]) < 32: - secret += random.choice(WORDS) + "-" + word_count = 0 + while word_count < SENDER_LENGTH + PASSWORD_LENGTH or len(secret[SENDER_LENGTH:]) < 32: + word = random.choice(WORDS) + print(pattern.match(word)) + if pattern.match(word) and len(word) < 10: + secret += word + "-" + word_count += 1 + secret = secret[:-1] self.secrets.append(secret) diff --git a/setup.py b/setup.py index e59614c..0d4a40f 100644 --- a/setup.py +++ b/setup.py @@ -12,6 +12,7 @@ setup( license='MIT', install_requires=[ 'wheel', + 'regex', 'requests', 'pybase64', 'qrcode',