可以指定要生成的密码长度的Python代码,长度python,可以指定要生成的密码长度
可以指定要生成的密码长度的Python代码,长度python,可以指定要生成的密码长度
可以指定要生成的密码长度的Python代码
from os import urandomfrom random import choicechar_set = {'small': 'abcdefghijklmnopqrstuvwxyz', 'nums': '0123456789', 'big': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'special': '^!\$%&/()=?{[]}+~#-_.:,;<>|\\' }def generate_pass(length=21): """Function to generate a password""" password = [] while len(password) < length: key = choice(char_set.keys()) a_char = urandom(1) if a_char in char_set[key]: if check_prev_char(password, char_set[key]): continue else: password.append(a_char) return ''.join(password)def check_prev_char(password, current_char_set): """Function to ensure that there are no consecutive UPPERCASE/lowercase/numbers/special-characters.""" index = len(password) if index == 0: return False else: prev_char = password[index - 1] if prev_char in current_char_set: return True else: return Falseif __name__ == '__main__': print generate_pass()
相关内容
- 小游戏Bomb Cacher,小游戏bombcacher,import sysim
- python字符串切片,拼接字符串处理文本.py,,#python字符串
- SSH代理连接器的Python代码,ssh连接器python,# -*- coding
- Python 生成随机中文验证码,,# -*- coding
- python中reduce用法,pythonreduce用法,>>> def myfu
- Python计算两个日期之间的相差的秒数,python日期,pytho
- python转换字符集,python字符集,def URLtoUTF
- python分割文件,python分割,#!/usr/bin/e
- Python文件的一些操作代码,python操作代码,#! /usr/bin/
- Python 装饰器实现的retry 出错重试,pythonretry,# 可以用来
评论关闭