密码不稳定,有更好的方法生成密码吗



导入随机导入字符串

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

我想知道是否有更好的方法来创建一个更安全的密码,而不仅仅是使用随机的ascii字符串

完成代码中的以下更改。

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!")

最新更新