Skip to content

Commit 59772f2

Browse files
committed
feat: Determine length of the randomly generated password
1 parent 10052ef commit 59772f2

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/pw_client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,14 @@ def create_backup(self):
6868
json.dump(self.pw_dict, pw_file_json)
6969

7070
@staticmethod
71-
def generate_random_password(special_characters=True):
72-
"""Generates a random password with 42 characters of any type (letters, digits, special characters)."""
71+
def generate_random_password(special_characters=True,
72+
password_length: int = 42) -> str:
73+
"""Generates a random password and returns it as a string."""
7374
digits = string.digits
7475
letters = string.ascii_letters
7576
punctuation = r"!#$%&()*+:,-./;<=>?@[]^_{|}~" if special_characters else None
7677
characters = digits + letters + punctuation
77-
random_password = ''.join(random.choice(characters) for i in range(42))
78+
random_password = ''.join(random.choice(characters) for i in range(password_length))
7879
return random_password
7980

8081
@staticmethod

src/pw_command.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ def main(parsed_args):
9292
return pw.create_section(args.section)
9393

9494
if args.generate_random_pw:
95-
random_pw = pw.generate_random_password()
95+
if args.input is not None:
96+
random_pw = pw.generate_random_password(password_length=int(args.input))
97+
else:
98+
random_pw = pw.generate_random_password()
9699
return pw.copy_and_print_pw(random_pw)
97100

98101
if args.input is None:

0 commit comments

Comments
 (0)