Skip to content

Added alternative way to generate password in password_generator.py #1415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions other/password_generator.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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...

Expand All @@ -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.]")


Expand Down