python 有严格规则的密码生成器
有严规则的密码生成器
import random from random import shuffle import string def generatepassword(): key='' for i in range(requirement['lowercase']): key=key+random.choice(lowercase) for i in range(requirement['uppercase']): key=key+random.choice(uppercase) for i in range(requirement['digits']): key=key+random.choice(digits) for i in range(requirement['special']): key=key+random.choice(special) for i in range(requirement['length']-requirement['lowercase']-requirement['uppercase']-requirement['digits']-requirement['special']): key=key+random.choice(fulltable) key=list(key) generatekey=random.shuffle(key) return ''.join(key) if __name__ == "__main__": print("默认的密码是16位,有2位大写,2位小写,2个特殊字符,2个数字\n") lowercase='abcdefghijklmnopqrstuvwxyz' uppercase='ABCDEFGHIJKLMNOPQRSTUVWXYZ' digits='0123456789' special= """!"#$%&'()*+,-./:;<=>?@[]^_`{|}~""" fulltable = lowercase+uppercase+digits+special requirement = {'lowercase' : 2 ,'uppercase': 2,'digits' :2,'special' : 2,'length':16} for j in range(10): print(generatepassword())
结果如下
默认的密码是16位,有2位大写,2位小写,2个特殊字符,2个数字
X:6u4G.k6%70*Gce
y^+P&4Q)>a=Rl'0N
c_R2@)eD?m74DP`-
QDOd0h#j#B{qlS79
PtN)9N^T7~J}oJaZ
$Q|6}70j~p<A~Roj
Ch;]T-2xK"8ei{10
0)y3~VsDDj={3/F!
>4{P'C2si,{8@6=K
w-G-(3Yt61Zwu!^I
Process finished with exit code 0
每天进步一点点,多思考,多总结
版权声明:本文为CNblog博主「zaituzhong」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。