import random def Range_get(num,alist): listout = [] while num > 0: listout.append(alist[random.randint(0,len(alist)-1)]) num-=1 return listout def Pwd_Maker(length,digit=0,uper=0,lower=0,string=0): if length <= 3 or digit+uper+lower+string > length: print("input wrong") digitlist = [str(i) for i in list(range(2,10))] #数字 uperlist = [chr(i) for i in list(range(65, 91))] #大写 lowerlist = [chr(i) for i in list(range(97,123))] #小写 stringlist = [chr(i) for i in [33,35,36,37,38,40,41,42]] #特殊字符 totallist = digitlist + digitlist + lowerlist + stringlist lefttime = length - digit - uper - lower - string resultlist = Range_get(digit,digitlist) + Range_get(uper,uperlist) \ + Range_get(lower,lowerlist) + Range_get(string,stringlist) + Range_get(lefttime,totallist) random.shuffle(resultlist) #shuffle 打乱从新排序 code = ''.join(resultlist) print(code) return code if __name__ == "__main__": Pwd_Maker(12,1,1,1) #(长度,至少有几个数字,至少有几个大写,至少有几个小写,至少有几个特殊字符)
密码生成器
最新推荐文章于 2024-04-19 21:14:03 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)