python生成强壮的密码生成器代码

代码语言:python

所属分类:其他

代码描述:python生成强壮的密码生成器代码,可指定密码位数,生成包含数组字母与特殊字符的密码。

代码标签: python 生成 强壮 密码 生成器 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

#!/usr/local/python3/bin/python3
# -*- coding: utf-8 -*
import string
from random import sample

def generate_strong_password(length, num, characters):
    pool = string.ascii_lowercase
    if num:
        for number in range(0, 10):
            pool += str(number)

    if characters:
        char = "!?=+-()"
        pool += char
# pool has all ascii_lowercase, puntuations and chars.

    while True:
        count_punc = 0
        count_num = 0
        pw = sample(pool,length)  # 获得个数为length的随机取样字符,return as a list.
        line = ""
        for item in pw:
            if item in string.punctuation:
                count_punc += 1  # The number of punctuation recorded
            elif item.isdigit():
                count_num +=1  # The number of numbers recorded
        if num == True and characters == True:.........完整代码请登录后点击上方下载按钮下载查看

网友评论0