随机密码生成器

 

随机密码生成器

2010-07-14 08:26:22
 标签: python 随机密码生成器    [ 推送到技术圈] 
 
版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章  原始出处 、作者信息和本声明。否则将追究法律责任。 http://5ydycm.blog.51cto.com/115934/349142
#!/usr/bin/env python
#Author:Badboy
#Notice:set a few passwords, () will fill in for the item, [] is optional

from random import choice
import string
import sys
specialchars='!@#$%^&*()'

def GenPasswd(length,chars=string.letters+string.digits+specialchars):
    return ''.join([choice(chars) for i in range(length)])

def usage():
    usages='''
Usage:
        ./mkpass (password length) [password numbers]
Example:
        ./mkpass 14 [4]
        '''
    print usages,

if __name__=="__main__":
    if len(sys.argv)==2:
        print GenPasswd(int(sys.argv[1]))
    elif len(sys.argv)==3:
        for i in range(int(sys.argv[2])):
             print GenPasswd(int(sys.argv[1]))
    else:
        usage()

执行结果图:
[root@test61 ~]# python mkpass.py

Usage:
        ./mkpass (password length) [password numbers] 
Example:
        ./mkpass 14 [4]

[root@test61 ~]# python mkpass.py 15
$BkIZ1OIHGSV35#

[root@test61 ~]# python mkpass.py 15 6
@eT)hMXt)f%jPn$
aHrKisQj@PaJ9nf
NabrAJXZsG(SfHK
U9jqjHkyBW4eIO0
JH8T3RCWGFHMlW6
X9ezN^k5PbIpVvm

你可能感兴趣的:(职场,休闲,随机密码生成器)