From bca2af0ed8abdc7b4300a91b39e3d121e0dd0c32 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Fri, 25 Nov 2022 19:23:14 -0500 Subject: [PATCH] pass_gen no longer recurses when the user gives invalid input Former-commit-id: c9756093cd861911b7f5dc05a71fc5a8b858c17e [formerly b10c1116407c6ee02138391533cc9904a555f318] Former-commit-id: c8b7974ec39c4e114578314814c5c2a982339736 --- lib/sshyp.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/sshyp.py b/lib/sshyp.py index 1f0d8b8..609b0ba 100755 --- a/lib/sshyp.py +++ b/lib/sshyp.py @@ -117,12 +117,17 @@ def string_gen(_complexity, _length): # generates and returns a random string b def pass_gen(): # prompts the user for necessary information to generate a password and passes it to string_gen - try: - _length = int(input('password length: ')) - except ValueError: - print(f"\n\u001b[38;5;9merror: a non-integer value was input for password length\u001b[0m\n") - _gen = pass_gen() - return _gen + _length = 9 + while True: + try: + _length = int(input('password length: ')) + except ValueError: + continue + else: + if _length < 1: + continue + else: + break _complexity = str(input('password complexity - simple (for compatibility) or complex (for security)? (s/C) ')) if _complexity != 's' and _complexity != 'S': _complexity = 'c'