python生成高强度密码

#以下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)

这里已经打包好,可以直接使用,免费提供给大家,使用方法在下方链接处。

https://download.csdn.net/download/KW__jiaoq/88464175

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

乘浪初心

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值