码迷,mamicode.com
首页 > 编程语言 > 详细

python生成密码小脚本

时间:2019-04-06 22:58:06      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:ascii   str   sci   clear   git   case   code   password   app   

script01
import re, random, string

count1 = int(input(‘请输入密码个数(必须大于0): ‘))
i = 0
passwds = []
while i < count1:
        tmp = random.sample(string.ascii_letters + string.digits, 10)
        passwd = ‘‘.join(tmp)
        if re.search(‘[0-9]‘, passwd) and re.search(‘[A-Z]‘, passwd) and re.search(‘[a-z]‘, passwd):
                passwds.append(passwd)
                i += 1
print(passwds)

script02

import string
import random

password_length = 16

def password_gen():
        l = []
        password = []
        dic = {
                0: string.digits,
                1: string.ascii_lowercase,
                2: string.ascii_uppercase,
                3: string.punctuation
        }

        while len(set(l)) < len(dic):
                l.clear()
                for _ in range(password_length):
                        l.append(random.randrange(0, len(dic)))
        for x in l:
                password.append(dic[x][random.randrange(0, len(dic[x]))])
        return ‘‘.join(password)

print(password_gen())

python生成密码小脚本

标签:ascii   str   sci   clear   git   case   code   password   app   

原文地址:https://blog.51cto.com/linux1991/2374788

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!