I am trying to create a password generator program where the user can select for example 8 special characters, 5 uppercase letters and 10 lowercase letters to be generated into a password. So for the above example the password would be 23 characters long with 8 special characters, 5 uppercase letters and 10 lowercase letters. I have the input created but what I am unsure of is how to get the program to know that for example 8 special characters will be 8 random characters from string.punctuation
for example.
This a sample code of how I am asking the user for their input.
while True:
try:
lower = list(string.ascii_lowercase)
lower_low = 6
lower_high = 24
lower_choice = int(input("How many lower case letters would you like in your password? "))
if lower_choice<lower_low or lower_choice>lower_high:
print("The selection must be" ,lower_low,"or higher or", lower_high,"and lower. Please choose again. ")
continue
break
except ValueError:
print("Invalid input. Please try again.")
print("You have choosen", lower_choice,"lowercase letters to be used in your password.")
My Python knowledge is very rusty but I tried creating a function like the one below to see if it would take user inputs and match the number to string.punctuation
for example and then create a random selection based on that but I am going wrong.
def password_gen():
special = (string.punctuation)
lower_choice = (string.ascii_lowercase)
upper_choice = (string.ascii_uppercase)
password = ''
for p in range(38):
password += random.choice(special+lower_choice+upper_choice)
return password
password = password_gen
print(password)
Where should I look first to point me in the right direction. Again my knowledge is very rusty so let me know if my direction is completely off on this.
Thanks