Python 生成MySQL 管理员随机复杂秘钥

来源:互联网 发布:linux 查看网络通不通 编辑:程序博客网 时间:2024/06/05 22:05

Python生成随机秘钥:

#!/usr/bin/pythonfrom random import choice as randomChoiceglobal passDataglobal passwordpassData = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',            'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',            'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',            'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',            #'!', '@', '#', '$', '%', '^', '&', '*', '-', '_', '=',             # 这里注释是因为有$#!^等特殊字符,在shell下的mysql命令行里面不识别,而且写普通的shell脚本以及python会面临转义以及被截断的问题,导致无法登陆,所以下面保留了*/-/_/= 4种特殊符号            '*', '-', '_', '=',            '+', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', ' ']# 这个是调试的方法,界面控制台让你输入,如果再其它代码里面引用,需要自带参数def newPass():    while True:        try:            passwdNum = int(raw_input("Enter max number of characters: "))        except TypeError:            print "Please enter a digit."            continue        break            get_password(passwdNum)def get_password(number):    password = []    number = int(number)    count = 0    print "\nGenerating password..."    while count != number:        password.append(randomChoice(passData))        count += 1    x = 0    p = ''    while x != len(password):        p = p + str(password[x])        x += 1        #print "Password generated.",    #print "Here's your %s character password. Note that there may be spaces: %s" % (len(password), p)    return p# 这里就是生成多少位秘钥,可以自己带参数print get_password(16)#newPass()



执行结果:

Generating password...exgODezzhoPwL_NNGenerating password...FxWbtKY=KKbczCPZGenerating password...NZIwnU8ij-w+FxwuGenerating password...BhbAgkBM0nparh8m
原创粉丝点击