| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
Hi, this forum is not here for homework help. It's only purpose is for helping students in this particular course. Sorry, I can't help with this. |
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.
{{title}}
Uh oh!
There was an error while loading. Please reload this page.
I'm very new to Python. Just started a college course on it in May 2023. Currently working on building and improving my first simple application as a Final Project for the class. It is a beginner project.
The main goal is to create a password generator that takes user input for how many passwords to generate and the length of the passwords. Then it will request input on whether the user wants to save the passwords to a file. There is a menu item ("list") that is supposed to list the saved passwords from the previously saved file, but the output shows nothing and loops back to the command input.
I would appreciate any feedback on what I'm doing wrong or can improve in the overall code.
I'm also very new to GitHub so forgive me but I'll post the code I have so far here:
import random, csv
#generates passwords with special requirements
def get_passwds(num, length):
#defines character set
lettrs = "qwertyuiopasdfghjklzxcvbnm"
numbrs = "0123456789"
spchar = "!@#$%&*"
uppr = lettrs.upper()
#combines character sets
pswdChars = lettrs + numbrs + spchar + uppr
pwds = []
for i in range(num):
pwd = "".join(random.sample(pswdChars, length))
#checks password for requirements and append to list of passwords while not (any(char.isdigit() for char in pwd) and any(char.isupper() for char in pwd) and any(char in spchar for char in pwd)): pwd = "".join(random.sample(pswdChars, length)) pwds.append(pwd)return pwds
def save_pwds(pwds):
with open("pwds.txt", "a") as file:
#writer = csv.writer(file)
for pwd in pwds:
file.write("{pwd}\n")
#writer.writerow([pwd])
def list_pwds():
with open("pwds.txt") as file:
#reader = csv.reader(file) for line in file: print(line, end="") print()def menu():
print("What would you like to do?")
print("list - List saved passwords.")
print("new - Get new passwords.")
print("exit - Leave the program.")
print()
#Application for generating a list of strong passwords at a length the user chooses
def main():
print(f"\tBrickWall\nThe Password Generator")
print()
menu()
more = "y"
while True:
command = input("Command: ")
if command == "new":
pwdnum = int(input("How Many Passwords: ")) pwdlength = int(input("Input Password Length: ")) pwds = get_passwds(pwdnum, pwdlength) for pwd in pwds: print(pwd) print() while True: savePwd = input("Would you like to save your passwords? (y/n): ") if savePwd.lower == "y": save_pwds(pwds) else: break elif command == "list": list_pwds(file) elif command == "exit": break else: print("Invalid Command! Please try again.\n") more = input("what would you like to do?: ") print()print("Bye")
if name == "main":
main()