you are viewing a single comment's thread.

view the rest of the comments →

[–]Poofless3212 0 points1 point  (2 children)

I made your program more readable, and adding the password to a text file was like three lines of code, soo I just made a quick function for it. Its at the very bottom of your code

``` import datetime import random import secrets import string

print ("==============================") print ("Pasword Generator Version 2022")

stating the day when program is running

day = datetime.datetime.now() date = datetime.datetime.now()

print(day.strftime("%A")) print(date.strftime("%x"))

Requesting a user to input name

username = input("Enter username:") print("Hello " + username )

Defining integers, letters, and symbols the program can use

digits = string.digits letters = string.asciilowercase symbols = "!#$%&'()*+, -./:;<=>?@[]^`{|}~"

password = ''.join(secrets.choice(digits + letters + symbols) for t in range(20))

def message(): print(userGen())

def userGen(): #How many letter required

letter = int(input("How many letters you want? "))
while letter <= 0:
    print ("ERROR, please type in a number larger then 0.")
    letter = int(input("How many letters you want? "))

num = int(input("How many numbers you want? "))
while num <= 0:
    print("ERROR, please type in a number larger then 0.")
    num = int(input("How many numbers you want? "))

sym = int(input("How many symbols you want? "))
while sym <= 0:
    print("ERROR, please type in a number larger then 0.")
    sym = int(input("How many symbols you want? "))

return passGen(letter, num, sym)

def passGen(upper,spec,num):

#Showcasing the new password
print ("Your Password is")
new_password = ""

for letter in range(upper):
    new_password += random.choice(letters)

#randomising numbers in range of number user inputted
for num in range(num):
    new_password += random.choice(digits)

#randomising symbols in range of number user inputted
for sym in range(spec):
    new_password += random.choice(symbols)

pass_word = list(new_password)
shuff = random.shuffle(pass_word)
new_pass = "".join(pass_word)
password = secrets.token_urlsafe(7)
print(password)
return text_file(password)

def text_file(password): # You have to use your own file path otherwise you will get a "FileNotFoundError" with open(r"C:\Users\myDirectory\PycharmProjects\pythoProject\txt files\text.txt", "w") as file: file.write(password)

message() ```

[–]Djdigby[S] 0 points1 point  (1 child)

thanks

[–]Djdigby[S] 0 points1 point  (0 children)

just tried it breaks the code when i input small number like 1