logo

数字,字母,特殊字符去除了string.punctuation里面部分字符

#! /usr/bin/env python   

import string
from os import urandom
from random import choice

spstr = '$%&()+,-.:;<=>@[]'
passwd_length = 20
passwd_count = 10
passwd_seed = string.digits + string.ascii_letters + spstr

def generate_passwd():
    '''Function to generate a password'''
    passwd = []
    while (len(passwd) < passwd_length):
        passwd.append(choice(passwd_seed))
    return ''.join(passwd)
    
if __name__ == '__main__':
    #print_string_constants()
    for i in range(0, passwd_count):
        print generate_passwd()
# ./passwd.py 
>DQI,YYH-)O1+1OZO=.%
cZ7F5N0)mE7ZLqa[tmfK
lF2EFW8Qu,Pu9e7MXP$)
7wOkkg-5Ro+PWO5[5AHi
d>NjcMdaPFDSoTyt<w6G
NtZNAH-G;$lFF%Z[fV2%
fh<>7n41kYPo%E[)n]7Z
0QhiK9.QTZXm15OELmeR
&35p5eJnEVUG[z75]Sv4
,J&4CAwOVNS;pVIQx]]6

参考

0 回复
需要 登录 后方可回复, 如果你还没有账号你可以 注册 一个帐号。