From 67aa3cfb4dd50e1d6feff6a36f630b374e2ab922 Mon Sep 17 00:00:00 2001 From: akankshamahajan99 <47140026+akankshamahajan99@users.noreply.github.com> Date: Tue, 22 Oct 2019 01:35:12 +0530 Subject: [PATCH] Added alternative way to generate password in password_generator.py (#1415) --- other/password_generator.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/other/password_generator.py b/other/password_generator.py index f72686bfb..b4c7999ca 100644 --- a/other/password_generator.py +++ b/other/password_generator.py @@ -1,5 +1,5 @@ """Password generator allows you to generate a random password of length N.""" -from random import choice +from random import choice, shuffle from string import ascii_letters, digits, punctuation @@ -26,9 +26,22 @@ def password_generator(length=8): def alternative_password_generator(ctbi, i): # Password generator = full boot with random_number, random_letters, and # random_character FUNCTIONS - pass # Put your code here... - + # Put your code here... + i = i - len(ctbi) + quotient = int(i / 3) + remainder = i % 3 + #chars = ctbi + random_letters(ascii_letters, i / 3 + remainder) + random_number(digits, i / 3) + random_characters(punctuation, i / 3) + chars = ctbi + random(ascii_letters, quotient + remainder) + random(digits, quotient) + random(punctuation, quotient) + chars = list(chars) + shuffle(chars) + return "".join(chars) + + #random is a generalised function for letters, characters and numbers +def random(ctbi, i): + return "".join(choice(ctbi) for x in range(i)) + + def random_number(ctbi, i): pass # Put your code here... @@ -43,7 +56,9 @@ def random_characters(ctbi, i): def main(): length = int(input("Please indicate the max length of your password: ").strip()) + ctbi = input("Please indicate the characters that must be in your password: ").strip() print("Password generated:", password_generator(length)) + print("Alternative Password generated:", alternative_password_generator(ctbi, length)) print("[If you are thinking of using this passsword, You better save it.]")