Fixed user being served complexity prompts multiple times when password generation is attempted more than once

This commit is contained in:
2022-05-15 03:42:16 -04:00
parent 99e0d5f666
commit 2f5080fec0
+14 -11
View File
@@ -74,19 +74,22 @@ def shm_gen(): # generates a random temporary folder for security and returns r
def pass_gen():
def _pass_gen_function(__complexity, __length):
if __complexity.lower() == 's':
__character_pool = string.ascii_letters + string.digits
else:
__character_pool = string.ascii_letters + string.digits + string.punctuation
__gen = ''.join(random.SystemRandom().choice(__character_pool) for _ in range(__length))
__min_special, __special = round(.2 * __length), 0
for __character in __gen:
if not __character.isalpha():
__special += 1
if __special < __min_special:
__gen = _pass_gen_function(__complexity, __length)
return __gen
_length = int(input('How many characters should be in the password? '))
_complexity = str(input('Should the password be simple (for compatibility) or complex (for security)? (s/C) '))
if _complexity.lower() == 's':
_complexity = string.ascii_letters + string.digits
else:
_complexity = string.ascii_letters + string.digits + string.punctuation
_gen = ''.join(random.SystemRandom().choice(_complexity) for _ in range(_length))
_min_special, _special = round(.2 * _length), 0
for _character in _gen:
if not _character.isalpha():
_special += 1
if _special < _min_special:
_gen = pass_gen()
_gen = _pass_gen_function(_complexity, _length)
return _gen