美文网首页
2021-12-13密码生成器

2021-12-13密码生成器

作者: XH_hector | 来源:发表于2021-12-13 12:10 被阅读0次

    起因

    周末登录一个网站要求修改密码,至少16位大小写,特殊字符之类的。我的常用密码平时不超过8位,用两次加起来也没能修改成功,就想通过软件生成密码。

    思路

    1. 输入网址、用户名、生成密码的位数
    2. 生成密码确保包含大小写字符、特殊字符、数字
    3. 网址、用户名、密码、生成日期保存到EXCEL中
    4. 密码自动复制到粘贴板
    5. 借助和彩云的同步盘功能,可以代替Lastpass密码管理器的功能。

    代码

    import sys
    sys.path.append(r'E:\python\venv\Lib\site-packages') # 代码是用pycharm写的,复制到桌面后需要添加环境。
    import string
    import random
    import pyperclip
    from  openpyxl import load_workbook
    import datetime
    def creatpassword(wangzhi,login,longPassword):
        global passWord
        str_lowercase = string.ascii_lowercase
        str_uppercase = string.ascii_uppercase
        str_digits = string.digits
        str_punc = string.punctuation
        str_all = str_lowercase + str_uppercase + str_digits + str_punc
        List = []
        for i in str_all:
            List.append(i)
        random.shuffle(List)
        count1 = count2 = count3 = count4 = 0
    
        while count1 == 0 or count2 == 0 or count3 == 0 or count4 == 0:
            passWord = random.sample(List, longPassword)
            count1 = 0
            count2 = 0
            count3 = 0
            count4 = 0
            for m in passWord:
                if m in str_uppercase:
                    count1 = 1
                    break
            for n in passWord:
                if n in str_lowercase:
                    count2 = 1
                    break
            for x in passWord:
                if x in str_punc:
                    count3 = 1
                    break
            for y in passWord:
                if y in str_digits:
                    count4 = 1
                    break
        return ''.join(passWord)
    def writexlsx(shuju):
        wb = load_workbook(r'E:\python\密码生成\password.xlsx')
        ws = wb.active
        ws.append(shuju)
        wb.save('E:\python\密码生成\password.xlsx')
        wb.close()
    if __name__ == '__main__':
        wangzhi = input('请输入网址:')
        login = input('请输入用户名:')
        longPassword = int(input('请输入密码长度:'))
        password = creatpassword(wangzhi, login, longPassword)
        shuju = [wangzhi,login,longPassword,password,datetime.date.today()]
        writexlsx(shuju)
        pyperclip.copy(password)
    
    image.png

    相关文章

      网友评论

          本文标题:2021-12-13密码生成器

          本文链接:https://www.haomeiwen.com/subject/vlyjfrtx.html