#以下secrets、string、os、datetime,需要安装,安装步骤省略。
import secrets
import string
import os
import datetime
# 获取时间
dt = datetime.datetime.now()
t = str(dt.year) + '年' + str(dt.month) + '月' + str(dt.day) + '日'
# t 就是把年月日拼接起来
print()
# 输入密码的重复数,默认是两个字母,两个数字,两个特殊符号,重复3次,案例 重复三次aa11..aa11..aa11.. ,重复1次 aa11..
ABC = input("字母大小写个数:")
digit = input("数字个数:")
Ss = input("特殊符号个数:")
Repetitions0 = input("重复次数:")
if Repetitions0 == "":
print("重复次数默认为3")
else:
Repetitions = int(Repetitions0)+1
# 默认值可修改
if ABC == "":
ABC = 2
if digit == "":
digit = 2
if Ss == "":
Ss = 2
if Repetitions0 == "":
Repetitions = 3
Repetitions = int(Repetitions)+1
# 控制获取字母,数字,特殊符号,随机个数
def a(s1, s2, s3):
a1 = ''.join(secrets.choice(string.ascii_letters) for i1 in range(int(s1)))
a2 = ''.join(secrets.choice(string.digits) for i2 in range(int(s2)))
a3 = ''.join(secrets.choice(string.punctuation) for i3 in range(int(s3)))
a4 = a1 + a2 + a3
return a4
# 控制重复获取随机密码
b = []
for i in range(1, int(Repetitions)):
if i == int(Repetitions):
break
else:
b.append(a(ABC, digit, Ss))
print('共' + str(len(''.join(b))) + '位', '密码:' + ''.join(b))
# 获取当前路径,生成一个密码本.txt,保存密码
current_path = os.getcwd()
print(current_path)
with open(f'{current_path}/密码本.txt', 'a') as f:
print(f"{t}", file=f)
with open(f'{current_path}/密码本.txt', 'a') as f:
print(f"共{str(len(''.join(b)))}位,密码:-----{''.join(b)}-----", file=f)
这里已经打包好,可以直接使用,免费提供给大家,使用方法在下方链接处。