python生成随机复杂可靠的密码
import string import random # 标点符号库 punctuation_store = string.punctuation # 大写字母库 ascii_uppercase_store = string.ascii_uppercase # 小写字母库 ascii_lowercase_store = string.ascii_lowercase # 数字字母库 digits_store = string.digits # 全部库 all_store = punctuation_store + ascii_uppercase_store + ascii_lowercase_store + digits_store if __name__ == '__main__': result = "" total = random.randint(8, 12) upper_string = random.choice(ascii_uppercase_store) lower_string = ''.join(random.sample(ascii_lowercase_store, 2)) digits_string = str(random.choice(list(range(1, 6)))) + str(random.choice(list(range(6, 10)))) punctuation_string = random.choice(ascii_lowercase_store) result = "".join([result, upper_string, lower_string, digits_string, punctuation_string]) current_len = len(result) need_len = total - current_len result_ext = ''.join(random.sample(all_store, need_len)) result = result + result_ext result = list(result) random.shuffle(result) result = ''.join(result) print(result)
原创文章,转载请注明出处:http://124.221.219.47/article/pas/