Python 生成MySQL 管理员随机复杂秘钥
2017-10-25 13:14
459 查看
Python生成随机秘钥:
执行结果:
#!/usr/bin/python from random import choice as randomChoice global passData global password passData = ['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_NN Generating password... FxWbtKY=KKbczCPZ Generating password... NZIwnU8ij-w+Fxwu Generating password... BhbAgkBM0nparh8m
相关文章推荐
- python生成随机数据插入mysql
- Python 每日练习 03 把将随机生成的200 个激活码保存在mysql中
- Python随机生成指定长度字符串并保存到mysql中
- Python生成随机数组的方法小结
- 利用Python生成随机密码
- Python随机生成一个6位的验证码代码分享
- C#生成一个复杂的验证码、背景随机、字体随机、中英文数字随机
- python 随机生成 01 字符串
- 利用Python如何生成随机密码
- 在 MySQL 中根据规则生成随机密码
- 如何利用Python生成随机密码
- mysql生成随机时间
- Python+Mysql生成zabbix统计数据 推荐
- python 怎么随机生成15位随机数字
- python随机生成字符串
- python 生成随机密码
- python.matplotlib/random.choice学习范例-随机生成点图
- Python生成8位随机字符串的一些方法
- Python自动生成随机身份证号码
- mysql生成随机字符串