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
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)

View File

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