Unstable password, is there a better way to generate passwords?

Question:

import random
import string

lowercase = [string.ascii_lowercase]
uppercase = [string.ascii_uppercase]
number = [string.digits]
symbols = [string.punctuation]
password_outputs = string.ascii_lowercase + string.ascii_uppercase + string.digits +string.punctuation

I was wondering if there was a better way to create a more secure password then just using the ascii strings with random

Asked By: noobcoder42

||

Answers:

Done following changes in your code.

import random
import string

lowercase = [string.ascii_lowercase]
uppercase = [string.ascii_uppercase]
number = [string.digits]
symbols = [string.punctuation]
password_outputs = string.ascii_lowercase + string.ascii_uppercase + string.digits +string.punctuation

print("Welcome to the RPG!")

gen_password=''
stop = False
num_char = 0. # include this line if you want that earlier user entered 3 and in next iteration 5 so total you want 8 character password if you only want 5 character password then you can remove this line
while not stop:
    gen_password='' # each time it will default to empty 
    num_char += int(input('Enter in the ammount of characters for the desired password: '))
    while num_char > 0:
        rand_char = random.choice(password_outputs)
        gen_password += rand_char
        num_char -= 1
            #basically a redstone repeater that decreases in value until it hits 0 and can contiue. User able to pick start value
        if num_char == 0:
            print(gen_password)
            #ensures that only the final product of while loop is printed
    #if num_char != int:
        #stop = False
        #want to make it more secure against non-integer inputs, not sure how to go about this

    user_continue = input('Would you like to generate a longer password? (y/n): ')
    if user_continue == 'y':
        stop = False
    elif user_continue == 'n':
        stop = True
    else:
        print('Invalid Operation, running generator again')
        stop = False

print("Have a nice day!")
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.