用tkinter GUI判断密码强度
时间: 2024-05-24 20:06:17 浏览: 165
以下是一个使用tkinter GUI判断密码强度的例子:
```python
import tkinter as tk
import pyperclip
import string
import random
def getPassword():
password = generatePassword()
pyperclip.copy(password)
strength = checkPasswordStrength(password)
resultLabel.config(text="生成的密码已复制到剪切板,密码强度为:" + strength)
def generatePassword():
length = 16
chars = string.ascii_letters + string.digits + string.punctuation
password = ''.join(random.choice(chars) for i in range(length))
return password
def checkPasswordStrength(password):
length = len(password)
if length < 8:
return "弱"
elif length < 12:
return "中"
else:
return "强"
root = tk.Tk()
root.title("密码生成器")
titleLabel = tk.Label(root, text="密码生成器", font=("Arial", 20))
titleLabel.pack(pady=10)
generateButton = tk.Button(root, text="生成密码并复制到剪切板", command=getPassword)
generateButton.pack(pady=10)
resultLabel = tk.Label(root, text="")
resultLabel.pack(pady=10)
root.mainloop()
```
该程序会生成一个16位的随机密码,并将其复制到剪切板中。同时,它会根据密码的长度判断密码的强度,并在GUI中显示出来。
阅读全文