[Python] 纯文本查看 复制代码
global gly_login
gly_login = 0
def main():
def isgly():
try:
with open("gly.txt") as f:
if f.read() == "enabled":
return True
else:
return False
except:
return False
import os
import tkinter as tk
import tkinter.messagebox
from Crypto.Cipher import AES
import base64
import sys
import ttkbootstrap as ttk
import hashlib
try:
import easygui
except:
tk.messagebox.showerror("错误", "无法导入easygui模块!")
sys.exit()
import subprocess
BLOCK_SIZE = 16 # Bytes
pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * chr(
BLOCK_SIZE - len(s) % BLOCK_SIZE
)
unpad = lambda s: s[: -ord(s[len(s) - 1 :])]
def aesEncrypt(key, data):
key = key.encode("utf8")
data = pad(data)
cipher = AES.new(key, AES.MODE_ECB)
result = cipher.encrypt(data.encode())
encodestrs = base64.b64encode(result)
enctext = encodestrs.decode("utf8")
return enctext
def aesDecrypt(key, data):
"""
:param key: 密钥
:param data: 加密后的数据(密文)
:return:明文
"""
key = key.encode("utf8")
data = base64.b64decode(data)
cipher = AES.new(key, AES.MODE_ECB)
text_decrypted = unpad(cipher.decrypt(data))
text_decrypted = text_decrypted.decode("utf8")
return text_decrypted
def saveinfo():
with open("nameandpwd.txt", "w") as f:
f.write(aesEncrypt(key="taoyuanhang66666", data=str(nameandpwd)))
def readinfo():
with open("nameandpwd.txt") as f:
nameandpwd = eval(aesDecrypt(key="taoyuanhang66666", data=f.read()))
win = ttk.Window(alpha=0.8, themename="darkly")
win.attributes("-topmost", 1)
win.title("用户登录 8.0")
win.geometry("250x140")
win.resizable(width=False, height=False)
try:
win.iconbitmap("tubiao.ico")
except:
pass
try:
with open("nameandpwd.txt") as f:
nameandpwd = eval(aesDecrypt(key="taoyuanhang66666", data=f.read()))
except:
with open("nameandpwd.txt", "w") as f:
f.write(aesEncrypt(key="taoyuanhang66666", data="{'admin': 'python@16'}"))
nameandpwd = {"admin": "python@16"}
var_Name = ttk.StringVar()
var_Name.set("")
var_Pwd = ttk.StringVar()
var_Pwd.set("")
def about(a):
if a == "1":
tk.messagebox.showinfo(
"About",
"""用户登录(管理员) by 陶远航
版本:8.0 公测版
程序及源代码仅供学习交流,
未经作者允许不可用于商业用途!
""",
)
elif a == "2":
tk.messagebox.showinfo(
"About",
"""你正在管理员模式查看关于
用户登录(管理员) by 陶远航
版本:8.0 公测版.
程序及源代码仅供学习交流,
未经作者允许不可用于商业用途!
""",
)
def feedback():
import smtplib
import re
from os import environ
from os.path import exists
from platform import system, node
from time import strftime
from email.mime.text import MIMEText
from email.utils import formataddr
from random import randint
from easygui import enterbox
title = "用户登录 8.0"
my_sender = "advance_software@126.com"
my_pass = "QFAQPLFQZRZBMVWQ"
dt = strftime("%Y-%m-%d %H:%M:%S")
my_user = "taoyuanhang66@outlook.com"
username = environ["USERNAME"]
system = system()
computer = node()
number = enterbox("请输入反馈内容:")
err = Exception
def mail():
global err
ret = True
try:
msg = MIMEText(number, "plain", "utf-8")
msg["From"] = formataddr([enterbox("请输入名字:"), my_sender])
msg["To"] = formataddr(["", my_user])
msg["Subject"] = "用户使用反馈"
server = smtplib.SMTP_SSL("smtp.126.com", 465)
server.login(my_sender, my_pass)
server.sendmail(
my_sender,
[
my_user,
],
msg.as_string(),
)
server.quit()
except Exception as e:
ret = False
err = str(e)
return ret
def checkmail(email):
reg = "\w+[@][a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+"
result = re.findall(reg, email)
if result:
ret = mail()
if ret:
tk.messagebox.showinfo("反馈", "发送成功!")
else:
tk.messagebox.showerror("反馈", "邮件发送失败!")
else:
tk.messagebox.showerror("用户登录", "您的输入不合法,请重新输入!")
if __name__ == "__main__":
checkmail(my_user)
def tools(name, is_gly=False):
import easygui
while True:
list = [
"打开记事本",
"简易计算器",
"修改密码",
"重启主窗口",
"摄氏度转华氏度",
"华氏度转摄氏度",
"关于",
"意见反馈",
"用户信息",
"退出",
]
if is_gly == True:
list = [
"打开记事本",
"简易计算器",
"重启主窗口",
"摄氏度转华氏度",
"华氏度转摄氏度",
"关于",
"意见反馈",
"用户信息",
"退出",
]
choise = easygui.choicebox(msg="选择小工具", title="选择小工具", choices=list)
if choise == "打开记事本":
subprocess.Popen(["notepad.exe"])
elif choise == "简易计算器":
try:
shizi = easygui.enterbox("输入要计算的式子:")
tk.messagebox.showinfo("简易计算器", eval(shizi))
except:
tk.messagebox.showerror("简易计算器", "输入错误,请重新输入")
elif choise == "退出":
if tk.messagebox.askyesno("小工具", "确定退出吗?") == True:
break
else:
pass
elif choise == "意见反馈":
feedback()
elif choise == "摄氏度转华氏度":
try:
ssd = float(easygui.enterbox("请输入摄氏度:"))
hsd = format(ssd * 1.8 + 32, ".3f")
tk.messagebox.showinfo("摄氏度转华氏度", hsd)
except:
tk.messagebox.showinfo("摄氏度转华氏度", "请输入正确的值")
elif choise == "华氏度转摄氏度":
try:
hsd = float(easygui.enterbox("请输入华氏度:"))
ssd = format((hsd - 32) / 1.8, ".3f")
tk.messagebox.showinfo("华氏度转摄氏度", ssd)
except:
tk.messagebox.showinfo("摄氏度转华氏度", "请输入正确的值")
elif choise == "小游戏":
try:
os.system("plane_main.exe")
except:
tk.messagebox.showerror("错误", "没有小游戏")
elif choise == "关于":
if is_gly == True:
about("2")
else:
about("1")
elif choise == "修改密码":
try:
pwd = nameandpwd[name]
except:
tk.messagebox.showerror("", "未找到此用户!")
if easygui.enterbox("请输入旧密码") == pwd:
pwd_new = easygui.enterbox("请输入新密码")
nameandpwd[name] = pwd_new
with open("nameandpwd.txt", "w") as f:
f.write(
aesEncrypt(key="taoyuanhang66666", data=str(nameandpwd))
)
tk.messagebox.showinfo("", "修改成功!")
else:
tk.messagebox.showerror("", "密码错误!")
elif choise == "用户信息":
tk.messagebox.showinfo("用户信息", ("用户名:", name))
elif choise == "重启主窗口":
main()
break
else:
if tk.messagebox.askyesno("小工具", "你确定要退出吗") == True:
break
else:
pass
def b():
try:
with open("a.txt") as f:
temp = f.read()
if temp == "ok":
with open("a.txt", "w") as f:
f.write("4")
tk.messagebox.showerror(title="用户登录", message="还有4次机会,错误次数过多会导致账户永久锁定!")
else:
try:
temp = int(temp)
except:
tk.messagebox.showerror(title="用户登录", message="账号异常!")
if temp == 1:
tk.messagebox.showerror(
title="用户登录", message="错误次数过多,账户已永久锁定,请重新注册!"
)
else:
temp = temp - 1
with open("a.txt", "w") as f:
f.write(str(temp))
tk.messagebox.showerror(
title="用户登录", message=("还有", str(temp), "次机会,错误次数过多会导致账户永久锁定!")
)
except:
with open("a.txt", "w") as f:
f.write("4")
tk.messagebox.showerror("用户登录", "还有4次机会,错误次数过多会导致账户永久锁定!")
def login():
try:
win.attributes("-topmost", 0)
except:
pass
try:
with open("nameandpwd.txt") as f:
nameandpwd = eval(aesDecrypt(key="taoyuanhang66666", data=f.read()))
except:
with open("nameandpwd.txt", "w") as f:
f.write(
aesEncrypt(key="taoyuanhang66666", data="{'admin': 'python@16'}")
)
nameandpwd = {"admin": "python@16"}
name = var_Name.get()
pwd = var_Pwd.get()
try:
if nameandpwd[name] == pwd:
if name.upper() == "SYSTEM":
tk.messagebox.showerror("错误", '不能以"SYSTEM"为用户名')
else:
tk.messagebox.showinfo("用户登录", "登录成功!")
with open("a.txt", "w") as f:
f.write("ok")
win.quit()
win.destroy()
tools(name)
else:
tk.messagebox.showerror("用户登录", "密码错误!")
except:
tk.messagebox.showerror("用户登录", "没有此用户!")
def zhuce():
try:
win.attributes("-topmost", 0)
except:
pass
try:
win.attributes("-topmost", 0)
except:
pass
try:
with open("nameandpwd.txt") as f:
nameandpwd = eval(aesDecrypt(key="taoyuanhang66666", data=f.read()))
except:
with open("nameandpwd.txt", "w") as f:
f.write(
aesEncrypt(key="taoyuanhang66666", data="{'admin': 'python@16'}")
)
nameandpwd = {"admin": "python@16"}
name = var_Name.get()
pwd = var_Pwd.get()
try:
nameandpwd[name]
tk.messagebox.showerror("", "该用户名已被注册,请换一个吧!")
except:
if name == "" or pwd == "":
tk.messagebox.showerror(title="警告", message="用户名或密码不能为空")
if name.upper() == "SYSTEM":
tk.messagebox.showerror(title="警告", message='不能以"SYSTEM"作为用户名')
else:
if len(pwd) <= 5:
tk.messagebox.showinfo(title="警告", message="密码太短了,长度不能低于6个字符!")
elif pwd.count(pwd[0]) == len(pwd):
tk.messagebox.showinfo(title="警告", message="密码不安全,换个不容易被猜到的密码吧!")
elif pwd in [
"A123456",
"a123456",
"a1234567",
"A1234567",
"Aa1234567",
"password",
"Password",
"password1",
"a123456",
"qwerty",
"password01",
"picture1",
]:
tk.messagebox.showinfo(title="警告", message="密码不安全,换个不容易被猜到的密码吧!")
else:
pwd2 = easygui.passwordbox("请再次输入密码:")
if pwd == pwd2:
nameandpwd[name] = pwd
with open("nameandpwd.txt", "w") as f:
f.write(
aesEncrypt(key="taoyuanhang66666", data=str(nameandpwd))
)
tk.messagebox.showinfo("注册", "注册成功!")
else:
tk.messagebox.showerror("注册", "密码不一致!")
def _quit():
try:
win.attributes("-topmost", 0)
except:
pass
import smtplib
import re
from os import environ
from os.path import exists
from platform import system, node
from time import strftime
from email.mime.text import MIMEText
from email.utils import formataddr
from random import randint
from easygui import enterbox
title = "用户登录 8.0"
my_sender = "advance_software@126.com"
my_pass = "QFAQPLFQZRZBMVWQ"
dt = strftime("%Y-%m-%d %H:%M:%S")
my_user = enterbox("请输入邮箱:")
username = environ["USERNAME"]
system = system()
computer = node()
number = randint(100000, 999999)
number = str(number)
err = Exception
def mail():
global err
ret = True
try:
msg = MIMEText(number, "plain", "utf-8")
msg["From"] = formataddr(["陶远航", my_sender])
msg["To"] = formataddr(["", my_user])
msg["Subject"] = "用户登录的验证码"
server = smtplib.SMTP_SSL("smtp.126.com", 465)
server.login(my_sender, my_pass)
server.sendmail(
my_sender,
[
my_user,
],
msg.as_string(),
)
server.quit()
except Exception as e:
ret = False
err = str(e)
return ret
def checkmail(email):
reg = "\w+[@][a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+"
result = re.findall(reg, email)
if result:
ret = mail()
if ret:
num = enterbox("发送成功!请耐心等待并输入您的验证码:", title)
if num == str(number):
tk.messagebox.showinfo("用户登录", "登录成功!")
win.quit()
win.destroy()
tools()
else:
tk.messagebox.showinfo("用户登录", "登录失败!")
else:
tk.messagebox.showerror("用户登录", "邮件发送失败!")
else:
tk.messagebox.showerror("用户登录", "您的输入不合法,请重新输入!")
if __name__ == "__main__":
checkmail(my_user)
def gly():
try:
with open("nameandpwd.txt") as f:
nameandpwd = eval(aesDecrypt(key="taoyuanhang66666", data=f.read()))
except:
with open("nameandpwd.txt", "w") as f:
f.write(
aesEncrypt(key="taoyuanhang66666", data="{'admin': 'python@16'}")
)
nameandpwd = {"admin": "python@16"}
if isgly():
listgly = [
"退出",
"注销账号",
"查看所有用户",
"添加账户",
"查看密码",
"强制登录",
"带有用户名的强制登录(高级)",
"关于",
]
else:
pass
while True:
if isgly():
choice = easygui.choicebox(msg="我是管理员", title="我是管理员", choices=listgly)
else:
tk.messagebox.showerror("", "你没有管理员权限,请退出!")
break
if choice == "注销账号":
readinfo()
if isgly():
pass
else:
tk.messagebox.showerror("", "你没有管理员权限,请退出!")
break
name = easygui.enterbox("请输入用户名", "请输入用户名")
try:
nameandpwd.pop(name)
with open("nameandpwd.txt", "w") as f:
f.write(
aesEncrypt(key="taoyuanhang66666", data=str(nameandpwd))
)
tk.messagebox.showinfo("注销", "注销成功!")
except:
tk.messagebox.showerror("错误", "没有此用户!")
elif choice == "查看所有用户":
readinfo()
if isgly():
pass
else:
tk.messagebox.showerror("", "你没有管理员权限,请退出!")
break
nms = list(nameandpwd.keys())
tk.messagebox.showinfo("用户", nms)
elif choice == "添加账户":
readinfo()
if isgly():
pass
else:
tk.messagebox.showerror("", "你没有管理员权限,请退出!")
break
name = easygui.enterbox("请输入用户名")
nameandpwd[name] = easygui.enterbox("请输入密码")
with open("nameandpwd.txt", "w") as f:
f.write(aesEncrypt(key="taoyuanhang66666", data=str(nameandpwd)))
tk.messagebox.showinfo("", "添加成功!")
elif choice == "查看密码":
readinfo()
if isgly():
pass
else:
tk.messagebox.showerror("", "你没有管理员权限,请退出!")
break
try:
tk.messagebox.showinfo(
"密码", nameandpwd[easygui.enterbox("请输入用户名", "请输入用户名")]
)
except:
tk.messagebox.showerror("警告", "没有此用户")
elif choice == "强制登录":
readinfo()
if isgly():
pass
else:
tk.messagebox.showerror("", "你没有管理员权限,请退出!")
break
try:
win.quit()
win.destroy()
except:
pass
tools("SYSTEM", is_gly=True)
elif choice == "带有用户名的强制登录(高级)":
readinfo()
if isgly():
pass
else:
tk.messagebox.showerror("", "你没有管理员权限,请退出!")
break
try:
win.quit()
win.destroy()
except:
pass
tools(easygui.enterbox("请输入登录的用户名"), is_gly=True)
elif choice == "关于":
if isgly():
pass
else:
tk.messagebox.showerror("", "你没有管理员权限,请退出!")
break
about("2")
else:
if tk.messagebox.askyesno("警告", "你确定要退出吗?"):
break
def winset():
winlist = ["更改标题", "将主窗口设置为可调整大小", "将主窗口设置为不可调整大小", "更改主窗口大小", "退出"]
while True:
choice = easygui.choicebox(msg="窗口设置", title="窗口设置", choices=winlist)
if choice == "更改标题":
win.title(easygui.enterbox("输入窗口标题", "输入窗口标题"))
elif choice == "将主窗口设置为可调整大小":
win.resizable(width=True, height=True)
elif choice == "将主窗口设置为不可调整大小":
win.resizable(width=False, height=False)
elif choice == "更改主窗口大小":
a = easygui.enterbox("输入窗口大小,如:250x150")
try:
win.geometry(a)
except:
tk.messagebox.showinfo("", "设置错误。注意:250x150中间的“x”要用乘号")
else:
break
def more():
try:
win.attributes("-topmost", 0)
except:
pass
try:
with open("nameandpwd.txt") as f:
nameandpwd = eval(aesDecrypt(key="taoyuanhang66666", data=f.read()))
except:
with open("nameandpwd.txt", "w") as f:
f.write(
aesEncrypt(key="taoyuanhang66666", data="{'admin': 'python@16'}")
)
nameandpwd = {"admin": "python@16"}
list = ["注销账号", "窗口设置", "窗口置顶", "取消窗口置顶", "管理员按钮激活", "取消激活管理员按钮", "退出"]
while True:
choice = easygui.choicebox(msg="更多", title="更多", choices=list)
if choice == "退出":
if tk.messagebox.askyesno("警告", "你确定要退出吗"):
break
elif choice == "注销账号":
readinfo()
name = easygui.enterbox("输入你要注销的用户名:", "注销")
pwd = easygui.passwordbox("输入此用户的密码:", "注销")
try:
pwd2 = nameandpwd[name]
if pwd == pwd2:
if tk.messagebox.askyesno("警告", "你确定要注销吗?"):
nameandpwd.pop(name)
with open("nameandpwd.txt", "w") as f:
f.write(
aesEncrypt(
key="taoyuanhang66666", data=str(nameandpwd)
)
)
tk.messagebox.showinfo("注销", "注销成功!")
else:
tk.messagebox.showerror("警告", "密码错误!")
except:
tk.messagebox.showerror("警告", "没有此用户!")
elif choice == "取消激活管理员按钮":
if tk.messagebox.askyesno("警告", "这将使你失去管理员权限,继续吗?"):
try:
with open("gly.txt") as f:
if f.read() == "enabled":
temp = True
else:
temp = False
except:
temp = False
if temp:
with open("gly.txt", "w") as f:
f.write("disabled")
but_gly = tk.Button(
win, text="我是管理员", command=glylogin, state="disabled"
)
but_gly.place(x=30, y=110, width=90, height=20)
tk.messagebox.showinfo("", "取消激活成功!")
else:
tk.messagebox.showinfo("", "你没有管理员权限")
elif choice == "窗口设置":
if mima():
winset()
elif choice == "管理员按钮激活":
try:
with open("gly.txt") as f:
temp = f.read()
except:
temp = ""
if temp == "enabled":
tk.messagebox.showinfo("", "您已激活,无需再次激活")
elif (
hashlib.md5(
str(easygui.passwordbox("请输入激活密码")).encode()
).hexdigest()
== "31cf31b94356a2a6137641698fdfe304"
):
with open("gly.txt", "w") as f:
f.write("enabled")
but_gly = tk.Button(win, text="我是管理员", command=glylogin)
but_gly.place(x=30, y=110, width=90, height=20)
tk.messagebox.showinfo("", "激活成功")
else:
tk.messagebox.showerror("", "密码错误")
elif choice == "窗口置顶":
win.attributes("-topmost", 1)
tk.messagebox.showinfo("", "置顶成功!")
elif choice == "取消窗口置顶":
win.attributes("-topmost", 0)
tk.messagebox.showinfo("", "取消置顶成功!")
else:
if tk.messagebox.askyesno("警告", "你确定要退出吗"):
break
def mima():
tk.messagebox.showinfo(
"管理员验证",
"""功能内测中或仅限管理员调试使用,
请确定你的管理员身份""",
)
glypwd = easygui.passwordbox("请输入密码:")
if (
hashlib.md5(str(glypwd).encode()).hexdigest()
== "fd2e8045450ce3baca670d5cc1b3cd5f"
):
glypwd = easygui.passwordbox("请输入第二层密码:")
if (
hashlib.md5(str(glypwd).encode()).hexdigest()
== "31cf31b94356a2a6137641698fdfe304"
):
return True
else:
tk.messagebox.showerror("", "密码错误!")
return False
else:
tk.messagebox.showerror("", "密码错误!")
return False
def glylogin():
if isgly():
try:
win.attributes("-topmost", 0)
except:
pass
global gly_login
if gly_login == 1:
tk.messagebox.showinfo("", "已确定你的管理员身份,已自动登录")
gly()
elif isgly():
if mima():
gly_login = 1
gly()
else:
if tk.messagebox.askyesno(
"",
"""管理员按钮未激活,您的使用将会受限.
若要体验全功能,请激活管理员按钮,是否获取管理员密码?""",
):
tk.messagebox.showinfo("获取管理员密码", "有兴趣的朋友可以尝试解密!")
else:
but_gly = tk.Button(win, text="我是管理员", command=glylogin, state="disabled")
but_gly.place(x=30, y=110, width=90, height=20)
tk.messagebox.showerror("", "你没有管理员权限,有兴趣的朋友可以尝试解密!")
labname = tk.Label(win, text="账号:", width=80)
labpwd = tk.Label(win, text="密码:", width=80)
entname = tk.Entry(win, width=100, textvariable=var_Name)
entpwd = tk.Entry(win, show="*", width=100, textvariable=var_Pwd)
but_Ok = tk.Button(win, text="登录", command=login)
but_Cancel = tk.Button(win, text="注册", command=zhuce)
but_quit = tk.Button(win, text="邮箱验证", command=_quit)
if isgly():
but_gly = tk.Button(win, text="我是管理员", command=glylogin)
else:
but_gly = tk.Button(win, text="我是管理员", command=glylogin)
but_more = tk.Button(win, text="更多", command=more)
labname.place(x=20, y=10, width=80, height=20)
labpwd.place(x=20, y=40, width=80, height=20)
entname.place(x=120, y=10, width=80, height=20)
entpwd.place(x=120, y=40, width=80, height=20)
but_Ok.place(x=30, y=80, width=50, height=20)
but_Cancel.place(x=100, y=80, width=50, height=20)
but_quit.place(x=160, y=80, width=70, height=20)
but_gly.place(x=30, y=110, width=90, height=20)
but_more.place(x=140, y=110, width=50, height=20)
def on_closing():
if tkinter.messagebox.askyesno("警告", "你确定要退出吗?"):
win.quit()
win.destroy()
win.protocol("WM_DELETE_WINDOW", on_closing)
win.mainloop()
main()