python高強度密碼生成器
一個python高強度密碼生成器,可以指定要生成的密碼長度
from os import urandom from random import choicecharset = {'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 False
if name == 'main': print generate_pass() </pre>
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!