Created
January 8, 2014 08:48
-
-
Save Nataila/8313743 to your computer and use it in GitHub Desktop.
自己写的一个密码生成脚本
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#coding=utf-8 | |
# Author: CC | |
# Created Time: Tue 07 Jan 2014 07:30:55 PM CST | |
#此脚本支持生成5位以上62以下的密码 | |
import string | |
import random | |
from optparse import OptionParser | |
def passwd_core(passwd_length): | |
passwd = [] | |
if int(passwd_length) <= 5: | |
print 'safe password length must greater than five' | |
else: | |
passwd_seed = string.digits + string.ascii_letters | |
for i in range(0, int(passwd_length)): | |
passwd.append(passwd_seed[random.randrange(0, 62)]) | |
print ''.join(passwd) | |
if __name__ == '__main__': | |
option = OptionParser() | |
option.add_option('-l', '--passwd_length', help='', default='8') | |
option, args = option.parse_args() | |
passwd_core(option.passwd_length) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment