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
This commit is contained in:
Raphael Maenle 2022-01-16 13:41:04 +01:00
parent 1e7301d919
commit 570a64f450
2 changed files with 10 additions and 4 deletions

View File

@ -76,12 +76,17 @@ class Bump:
return secrets return secrets
def generate_secret(self, secrets_file): def generate_secret(self, secrets_file):
pattern = re.compile('^[a-zA-Z]+$')
WORDS = r.get_random_words() WORDS = r.get_random_words()
secret = "" secret = ""
for _ in range(SENDER_LENGTH + PASSWORD_LENGTH): word_count = 0
secret += random.choice(WORDS) + "-" while word_count < SENDER_LENGTH + PASSWORD_LENGTH or len(secret[SENDER_LENGTH:]) < 32:
while len(secret[SENDER_LENGTH:]) < 32: word = random.choice(WORDS)
secret += random.choice(WORDS) + "-" print(pattern.match(word))
if pattern.match(word) and len(word) < 10:
secret += word + "-"
word_count += 1
secret = secret[:-1] secret = secret[:-1]
self.secrets.append(secret) self.secrets.append(secret)

View File

@ -12,6 +12,7 @@ setup(
license='MIT', license='MIT',
install_requires=[ install_requires=[
'wheel', 'wheel',
'regex',
'requests', 'requests',
'pybase64', 'pybase64',
'qrcode', 'qrcode',