欢迎光临 - 我的站长站,本站所有资源仅供学习与参考,禁止用于商业用途或从事违法行为!

python教程

密码强度检测Python源代码

python教程 我的站长站 2023-06-06 共49人阅读

一段非常简单的密码强度检测Python源代码,功能过于简单重构了遍,让它起码有点质量能拿出来分享。

import re
import tkinter as tk
class PasswordStrength:
    STRENGTHS = [
        ("无效的密码", "red"),
        ("非常弱的密码", "orange"),
        ("弱的密码", "yellow"),
        ("一般的密码", "green"),
        ("强的密码", "blue"),
        ("非常强的密码", "purple"),
    ]
    def __init__(self, password):
        self.password = password
        self.value = self.calculate_strength()
        self.text, self.color = self.STRENGTHS[self.value]
    def calculate_strength(self):
        strength = 0
        if len(self.password) >= 8:
            strength += 1
        if re.search(r"\d", self.password):
            strength += 1
        if re.search(r"[a-z]", self.password):
            strength += 1
        if re.search(r"[A-Z]", self.password):
            strength += 1
        if re.search(r"[!@#$%^&*()_+-=]", self.password):
            strength += 1
        return strength
class GUI(tk.Frame):
    def __init__(self, master):
        super().__init__(master)
        master.title("密码强度检测器")
        master.geometry(
            "400x200+{}+{}".format(
                (master.winfo_screenwidth() - 400) // 2,
                (master.winfo_screenheight() - 200) // 2,
            )
        )
        master.resizable(False, False)
        self.label = tk.Label(self, text="请输入密码:", font=("宋体", 16))
        self.entry = tk.Entry(self, show="*", font=("宋体", 16))
        self.entry.bind("<Return>", self.check)
        self.button = tk.Button(self, text="检测", font=("宋体", 16))
        self.button.bind("<Button-1>", self.check)
        self.result = tk.Label(self, text=" ", font=("宋体", 16), fg="gray")
        self.label.grid(row=0, column=0, padx=10, pady=10)
        self.entry.grid(row=0, column=1, padx=10, pady=10)
        self.button.grid(row=0, column=2, padx=10, pady=10)
        self.result.grid(row=1, column=0, columnspan=3, padx=10, pady=10)
        self.pack()
    def check(self, event):
        password = self.entry.get()
        strength = PasswordStrength(password)
        self.result.config(text=strength.text, fg=strength.color)
root = tk.Tk()
gui = GUI(root)
root.mainloop()
相关专题
Python
Python
2020-11-19 196

Python专题为了整理了关于Python学习资料,包含Python入门视频教程,Python视频教程,Python电子书,Python手册下载等等.

标签 Python源码
相关推荐
  • Python源码
  • Json压缩和格式化工具,附Python源码
    Json压缩和格式化工具,附Python源码

    软件介绍一款Json压缩和格式化工具,可以在线Json压缩和格式化。基于Python库开发,附上Python源码,GUI没有美化,巨丑。软件截图Python源码import jsonimport tkinter as tkdef json_compress(json_str...

    开发软件 34 10个月前
  • python打飞机小游戏源码+成品打包

    python源码用的pygame库,自带的random和os。程序运行需要的图片,声音和字体下载链接: https://pan.baidu.com/s/1KItG2usXOM_xcxcdHIixaw 提取码: qmweimport pygameimport randomimport os FPS = 60WIDTH = 500HEIGHT = 600 BLACK = (0, 0, 0)WHITE =...

    python教程 41 10个月前
  • 原创力文库Python爬虫下载源码

    # !/usr/bin/python# -*- coding: UTF-8 -*-import reimport jsonimport osimport shutilimport sysimport timeimport requestsimport img2pdffrom PIL import Image from alive_progress import alive_barfrom requests.exceptions import SSLErro...

    python教程 54 1年前
  • 讯飞听见语音转文字python源码

    讯飞听见语音转文字python源码,这个只能 转中文和英文,免费的转换不能超过3分钟。# -*- coding: utf-8 -*-# ☯ Author: ******# ☯ Email : ******@****.***# ☯ Date : 2021/06/24 20:13import osimport reimport timeimport randomimport logging...

    python教程 66 1年前
  • Python视频逐帧提取工具源码

    代码说明可以直接提取视频每一帧截图,只分享Python代码,自行打包。使用方法:将视频拉至窗口即可逐帧提取图像,默认生成在视频同目录下,效果看图。视频提取演示Python代码import osimport cv2import windndfrom tkinter import * def video_to_imgs(source...

    python教程 57 2年前