python_introduction/assets/pwd_cli.py

62 lines
1.6 KiB
Python
Raw Normal View History

2021-11-09 09:56:45 +01:00
import login_generator
def prompt():
"""
We prompt but you KNOW how this works!
"""
response = ""
while not response.isdigit():
response = input("how many login pairs would you like to create?")
return int(response)
def how_long():
"""
And again... (we could combine both prompts, but how?)
"""
response = ""
while not response.isdigit():
response = input("how long should the password be?")
return int(response)
def complex_or_not():
response = ""
while response.lower() not in ["y", "n"]:
response = input("you want complex passwords? (y/n)")
if response.lower() == "y":
return True
else:
return False
def create_login(length, complicated):
"""
We use our library to generate the username and password. The double return
might look confusing but just look at the for loop in the generate_logins
functions and you'll see how it unpacks...
"""
username = login_generator.generate_username()
password = login_generator.generate_password(length, complicated)
return username, password
def generate_logins(number, length, complicated):
"""
Easy no? But what does the i do? Do we really need it's value?
"""
for i in range(0, number):
username, password = create_login(length, complicated)
print("username {}: {}".format(i, username))
print("password {}: {}".format(i, password))
if __name__ == "__main__":
# Here we go!
number_of_logins = prompt()
complicted = complex_or_not()
length = how_long()
generate_logins(number_of_logins, length, complicted)