帮我看看这程序有什么问题吗?
源码(记得安装easygui模块):import tkinter as tk
import tkinter.messagebox
import hashlib
try:
import easygui
except:
tk.messagebox.showerror("无法导入easygui模块!")
import subprocess
win=tk.Tk()
win.title("用户登录 4.0")
win.geometry("250x140")
win.resizable(width=False, height=False)
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 = '用户登录 4.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()
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, , msg.as_string())
server.quit()
except Exception as e:
ret = False
err = str(e)
return ret
def checkmail(email):
reg = "\w+[@]+(\.+)+"
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():
import easygui
while 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("摄氏度转华氏度","请输入正确的值")
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("ok")
try:
win.iconbitmap("tubiao.ico")
except:
pass
var_Name=tk.StringVar()
var_Name.set('')
var_Pwd=tk.StringVar()
var_Pwd.set('')
try:
with open("name.txt") as f:
name=f.read()
except:
with open("name.txt","w") as f:
f.write(hashlib.md5(str("admin").encode()).hexdigest())
with open("name.txt") as f:
name = f.read()
try:
with open("password.txt") as f:
pwd=f.read()
except:
with open("password.txt","w") as f:
f.write(hashlib.md5(str("python@16").encode()).hexdigest())
with open("password.txt") as f:
pwd = f.read()
def login():
try:
with open("password.txt") as f:
pwd = f.read()
except:
with open("password.txt",'w') as f:
f.write(hashlib.md5(str('python@16').encode()).hexdigest())
pwd='python@16'
tk.messagebox.showinfo("提示",'检测到没有密码,已设为python@16。')
try:
with open("name.txt") as f:
name = f.read()
except:
with open("name.txt",'w') as f:
f.write(hashlib.md5(str('admin').encode()).hexdigest())
name='admin'
tk.messagebox.showinfo("提示",'检测到没有账号,已设为admin。')
name1=hashlib.md5(str(var_Name.get()).encode()).hexdigest()
pwd1=hashlib.md5(str(var_Pwd.get()).encode()).hexdigest()
if name1==name and pwd1==pwd:
try:
with open("a.txt", "r") as f:
temp=f.read()
if temp=='1':
tk.messagebox.showerror(title='用户登录', message='错误次数过多,账户已永久锁定!')
else:
tk.messagebox.showinfo(title='用户登录', message='登录成功!')
with open("a.txt", "w") as f:
f.write("ok")
win.quit()
win.destroy()
tools()
except:
tk.messagebox.showinfo(title='用户登录',message='登录成功!')
with open("a.txt","w") as f:
f.write("ok")
try:
win.quit()
win.destroy()
except:
pass
tools()
elif name1==name:
with open("a.txt") as f:
num=f.read()
if num!="1":
tk.messagebox.showerror(title='用户登录',message='密码有误!')
var_Pwd.set('')
b()
else:
with open("a.txt") as f:
num=f.read()
if num!="1":
tk.messagebox.showerror(title='用户登录',message='登录失败!')
var_Pwd.set('')
var_Name.set('')
b()
def zhuce():
if tk.messagebox.askyesno(title="警告",message="注册会覆盖原来的账号密码,确定注册吗?")==True:
name=var_Name.get()
pwd=var_Pwd.get()
if name=='' or pwd=='':
tk.messagebox.showerror(title="警告", message="用户名或密码不能为空")
else:
if len(pwd)<=5:
tk.messagebox.showinfo(title="警告", message="密码太短了,长度不能低于6个字符!")
elif pwd.count(pwd) == 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:
with open("name.txt", "w") as f:
f.write(hashlib.md5(str(name).encode()).hexdigest())
with open("password.txt","w") as f:
f.write(hashlib.md5(str(pwd).encode()).hexdigest())
tk.messagebox.showinfo("用户登录", "注册成功!")
with open("a.txt", 'w') as f:
f.write("ok")
var_Pwd.set("")
var_Name.set("")
else:
tk.messagebox.showerror(title='错误',message='密码输入错误!')
def _quit():
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 = '用户登录 3.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, , msg.as_string())
server.quit()
except Exception as e:
ret = False
err = str(e)
return ret
def checkmail(email):
reg = "\w+[@]+(\.+)+"
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():
import easygui
while True:
list = ['退出','强制更改账号密码','强制登录','封锁账号','解锁账号','反馈']
choise=easygui.choicebox(msg='管理员模式',title='管理员模式',choices=list)
if choise=='退出':
if tk.messagebox.askyesno("小工具","确定退出吗?")==True:
break
else:
pass
elif choise=='强制更改账号密码':
name=easygui.enterbox("请输入用户名:")
pwd=easygui.enterbox("请输入密码:")
with open("name.txt", "w") as f:
f.write(hashlib.md5(str(name).encode()).hexdigest())
with open("password.txt","w") as f:
f.write(hashlib.md5(str(pwd).encode()).hexdigest())
tk.messagebox.showinfo("用户登录", "更改成功!")
with open("a.txt", 'w') as f:
f.write("ok")
elif choise=='强制登录':
tk.messagebox.showinfo("用户登录", "登录成功!")
win.quit()
win.destroy()
tools()
elif choise=='反馈':
feedback()
elif choise=='封锁账号':
with open("a.txt","w") as f:
f.write("1")
tk.messagebox.showinfo('用户登录','封锁成功!')
elif choise=='解锁账号':
with open("a.txt","w") as f:
f.write("ok")
tk.messagebox.showinfo('用户登录','封锁成功!')
else:
if tk.messagebox.askyesno("小工具","确定退出吗?")==True:
break
else:
pass
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)
but_gly=tk.Button(win,text='我是管理员',command=gly)
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=80,y=110,width=90,height=20)
try:
with open("temp.txt") as f:
f.read()
except:
tk.messagebox.showinfo(title="用户登录", message="此程序在八上《信息技术》的基础上适当加了一些高级功能")
tk.messagebox.showinfo(title="用户登录", message="1.注册账号")
tk.messagebox.showinfo(title="用户登录", message="2.永久保存账号密码")
tk.messagebox.showinfo(title="用户登录", message="3.账号密码采用md5加密的方法存储")
tk.messagebox.showinfo(title="用户登录", message="4.账号或密码输入错误5次就会永久锁定该账户,需要重新注册")
tk.messagebox.showinfo(title="用户登录", message="5.打包成exe文件,打开即可运行")
tk.messagebox.showinfo(title="用户登录", message="6.识别密码的安全性")
tk.messagebox.showinfo(title="用户登录", message="7.支持邮箱验证!")
tk.messagebox.showinfo(title="用户登录", message="默认账号为admin,默认密码为python@16")
with open("temp.txt","w") as f:
f.write("1")
win.mainloop() 还有,怎么用python列出程序运行时产生的所有变量?
页:
[1]