最近1年自學了python,發現python的應用場景挺多,自己百度了加自己稍微修改,寫了段可以隨時生成指定長度的安全隨機密碼
#C:\Python36
#coding=utf-8
import string
from random import choice
passwd_length = int(input('The length of password: ')) #密碼的長度
passwd_count = int(input('The number of password lists: ')) #生成幾組密碼
symbols = '!@#$%&*+=' #定義使用哪些特殊字符,可以自己定義修改
passwd_seed = string.digits + string.ascii_letters + symbols #密碼的類型定義,數字+字母+特殊字符,(如果使用string.punctuation是使用所有的特殊字符,包括'.',不好識別)
def generate_passwd():
passwd = []
while (len(passwd) < passwd_length):
passwd.append(choice(passwd_seed))
return ''.join(passwd)
if __name__ == '__main__':
for i in range(0, passwd_count):
print(generate_passwd())