• python 生成随机密码


    #!/usr/bin/python3
    # -*- coding: utf-8 -*-
    import random,string
    src = string.ascii_letters + string.digits
    
    
    data = random.sample(src,0)
    data.extend(random.sample(string.digits, 3))#包含3个数字
    data.extend(random.sample(string.ascii_lowercase, 3))#包含3个小写字母
    data.extend(random.sample(string.ascii_uppercase, 2))#包含2个大写字母
    random.shuffle(data)
    passwd = ''.join(data)
    
    print(passwd)

     高级版

    #!/usr/bin/python3
    # -*- coding: utf-8 -*-
    import pyperclip
    import random
    import string
    import time
    
    while True:
        pw_type = input(" 生成的密码类型
    "
                        "【a 包含数字】、"
                        "【b 包含数字、小写字母】、"
                        "【c 包含数字、大小写字母】
    "
                        "【请输入 a 或 b 或 c】:")
    
        while True:
            if pw_type != "a" and pw_type != "b" and pw_type != "c":
                pw_type = input("【请输入 a 或 b 或 c】:")
            else:
                break
        print("")
    
        pw_len = input(" 生成的密码长度
    "
                       "【请输入4-10】:")
        while True:
            while True:
                if not pw_len.isdigit():
                    pw_len = input("【请输入4-10】:")
                else:
                    pw_len = int(pw_len)
                    break
    
            if 11 > pw_len > 3:
                break
            else:
                pw_len = input("【请输入4-10】:")
    
        if pw_type == "a":
            src = string.digits
            data = random.sample(src, pw_len)
        elif pw_type == "b":
            src = string.ascii_lowercase + string.digits
            data = random.sample(src, pw_len - 4)
            data.extend(random.sample(string.digits, 2))
            data.extend(random.sample(string.ascii_lowercase, 2))
        elif pw_type == "c":
            src = string.ascii_letters + string.digits
            data = random.sample(src, pw_len - 4)
            data.extend(random.sample(string.digits, 2))
            data.extend(random.sample(string.ascii_lowercase, 1))
            data.extend(random.sample(string.ascii_uppercase, 1))
    
        random.shuffle(data)
        passwd = ''.join(data)
    
        print("
    ",
              "密码:", passwd,
              "
    ")
    
        pyperclip.copy(passwd)
        print("已复制到剪贴板
    "
              "")

    在用pyinstaller打包成exe文件

    pip install pyinstaller

    pyinstaller.exe -F -c .passwd.py

  • 相关阅读:
    python报错Enable tracemalloc to get the object allocation traceback
    解决pycharm每次新建项目都要重新安装一些第三方库的问题
    创建一个CA证书
    [转载]oracle 12C 《服务器、客户端安装》
    [转载]Windows Server 2016中添加AD域控制器
    [转载]Windows Server 2016中部署AD
    虚拟机 VMware Workstation Pro 15.5.0 及永久激活密钥
    Oracle给查询结果增加序列号
    创建自定义ssl证书用于https
    js:getAttribute
  • 原文地址:https://www.cnblogs.com/37yan/p/8932844.html
Copyright © 2020-2023  润新知