#作品展示
#有没有大佬加下注释
import tkinter as tk
import os
import tkinter.messagebox
import hashlib
try:
import easygui
except:
tk.messagebox.showerror('用户登录',"没有easygui模块,请手动安装")
import time
win=tk.Tk()
win.title("用户登录 3.0")
win.geometry("250x130")
try:
win.iconbitmap("tubiao.ico")
except:
pass
var_Name=tk.StringVar()
var_Name.set('')
var_Pwd=tk.StringVar()
var_Pwd.set('')
try:
f=open("name.txt")
name=f.read()
f.close()
except:
f=open("name.txt","w")
f.write(hashlib.md5(str("admin").encode()).hexdigest())
f.close()
f = open("name.txt")
name = f.read()
f.close()
try:
f=open("password.txt")
pwd=f.read()
f.close()
except:
f=open("password.txt","w")
f.write(hashlib.md5(str("python@16").encode()).hexdigest())
f.close()
f = open("password.txt")
pwd = f.read()
f.close()
def login():
try:
f = open("password.txt")
pwd = f.read()
f.close()
except:
f = open("password.txt",'w')
f.write(hashlib.md5(str('python@16').encode()).hexdigest())
f.close()
pwd='python@16'
tk.messagebox.showinfo("提示",'检测到没有密码,已设为python@16。')
try:
f = open("name.txt")
name = f.read()
f.close()
except:
f = open("name.txt",'w')
f.write(hashlib.md5(str('admin').encode()).hexdigest())
f.close()
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:
f = open("a.txt", "r")
temp=f.read()
f.close()
if temp=='0':
tk.messagebox.showerror(title='用户登录', message='错误次数过多,账户已永久锁定!')
else:
tk.messagebox.showinfo(title='用户登录', message='登录成功!')
f = open("a.txt", "w")
f.write("ok")
f.close()
except:
tk.messagebox.showinfo(title='用户登录',message='登录成功!')
f=open("a.txt","w")
f.write("ok")
f.close()
elif name1==name:
tk.messagebox.showerror(title='用户登录',message='密码有误!')
var_Pwd.set('')
try:
f = open("a.txt", "r")
temp=f.read()
f.close()
if temp=='ok':
f = open("a.txt", 'w')
f.write("5")
f.close()
tk.messagebox.showerror(title='用户登录', message='还有6次机会,错误次数过多会导致账户永久锁定!')
elif temp=='5':
f = open("a.txt", 'w')
f.write("4")
f.close()
tk.messagebox.showerror(title='用户登录', message='还有5次机会,错误次数过多会导致账户永久锁定!')
elif temp == '4':
f = open("a.txt", 'w')
f.write("3")
f.close()
tk.messagebox.showerror(title='用户登录', message='还有4次机会,错误次数过多会导致账户永久锁定!')
elif temp=='3':
f = open("a.txt", 'w')
f.write("2")
f.close()
tk.messagebox.showerror(title='用户登录', message='还有3次机会,错误次数过多会导致账户永久锁定!')
elif temp=='2':
f = open("a.txt", 'w')
f.write("1")
f.close()
tk.messagebox.showerror(title='用户登录', message='还有2次机会,错误次数过多会导致账户永久锁定!')
elif temp=='1':
f = open("a.txt", 'w')
f.write("0")
f.close()
tk.messagebox.showerror(title='用户登录', message='还有1次机会,错误次数过多会导致账户永久锁定!')
else:
tk.messagebox.showerror(title='用户登录', message='错误次数过多,账户已永久锁定,请重新注册!')
except:
f =open("a.txt",'w')
f.write("5")
f.close()
else:
tk.messagebox.showerror(title='用户登录',message='登录失败!')
var_Pwd.set('')
var_Name.set('')
try:
f = open("a.txt", "r")
temp=f.read()
f.close()
if temp=='ok':
f = open("a.txt", 'w')
f.write("5")
f.close()
tk.messagebox.showerror(title='用户登录', message='还有6次机会,错误次数过多会导致账户永久锁定!')
elif temp=='5':
f = open("a.txt", 'w')
f.write("4")
f.close()
tk.messagebox.showerror(title='用户登录', message='还有5次机会,错误次数过多会导致账户永久锁定!')
elif temp == '4':
f = open("a.txt", 'w')
f.write("3")
f.close()
tk.messagebox.showerror(title='用户登录', message='还有4次机会,错误次数过多会导致账户永久锁定!')
elif temp=='3':
f = open("a.txt", 'w')
f.write("2")
f.close()
tk.messagebox.showerror(title='用户登录', message='还有3次机会,错误次数过多会导致账户永久锁定!')
elif temp=='2':
f = open("a.txt", 'w')
f.write("1")
f.close()
tk.messagebox.showerror(title='用户登录', message='还有2次机会,错误次数过多会导致账户永久锁定!')
elif temp=='1':
f = open("a.txt", 'w')
f.write("0")
f.close()
tk.messagebox.showerror(title='用户登录', message='还有1次机会,错误次数过多会导致账户永久锁定!')
else:
tk.messagebox.showerror(title='用户登录', message='错误次数过多,账户已永久锁定,请重新注册!')
except:
f =open("a.txt",'w')
f.write("5")
f.close()
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 pwd.isdecimal()==True:
tk.messagebox.showinfo(title="警告", message="密码不应该为纯数字,换个不容易被猜到的密码吧!")
elif len(pwd)<=5:
tk.messagebox.showinfo(title="警告", message="密码太短了,长度不能低于6个字符!")
elif pwd.count(pwd[0]) == len(pwd):
tk.messagebox.showinfo(title="警告", message="密码不安全,换个不容易被猜到的密码吧!")
elif pwd=='A123456':
tk.messagebox.showinfo(title="警告", message="密码不安全,换个不容易被猜到的密码吧!")
elif pwd=='a123456':
tk.messagebox.showinfo(title="警告", message="密码不安全,换个不容易被猜到的密码吧!")
elif pwd=='a1234567':
tk.messagebox.showinfo(title="警告", message="密码不安全,换个不容易被猜到的密码吧!")
elif pwd=='A1234567':
tk.messagebox.showinfo(title="警告", message="密码不安全,换个不容易被猜到的密码吧!")
elif pwd=='Aa1234567':
tk.messagebox.showinfo(title="警告", message="密码不安全,换个不容易被猜到的密码吧!")
elif pwd=='password':
tk.messagebox.showinfo(title="警告", message="密码不安全,换个不容易被猜到的密码吧!")
elif pwd=='Password':
tk.messagebox.showinfo(title="警告", message="密码不安全,换个不容易被猜到的密码吧!")
elif pwd=='password1':
tk.messagebox.showinfo(title="警告", message="密码不安全,换个不容易被猜到的密码吧!")
elif pwd=='a123456':
tk.messagebox.showinfo(title="警告", message="密码不安全,换个不容易被猜到的密码吧!")
elif pwd=='qwerty':
tk.messagebox.showinfo(title="警告", message="密码不安全,换个不容易被猜到的密码吧!")
elif pwd=='password01':
tk.messagebox.showinfo(title="警告", message="密码不安全,换个不容易被猜到的密码吧!")
elif pwd=='picture1':
tk.messagebox.showinfo(title="警告", message="密码不安全,换个不容易被猜到的密码吧!")
else:
tk.messagebox.showinfo('用户登录','为了安全,请确认输入的密码')
tk.messagebox.showinfo('用户登录','点击确定后请等待,程序会打开一个安全窗口')
time.sleep(1)
pwd2=easygui.passwordbox('请再次输入密码','用户登录')
if pwd==pwd2:
f = open("name.txt", "w")
f.write(hashlib.md5(str(name).encode()).hexdigest())
f.close()
f = open("password.txt", "w")
f.write(hashlib.md5(str(pwd).encode()).hexdigest())
f.close()
tk.messagebox.showinfo("用户登录", "注册成功!")
f = open("a.txt", 'w')
f.write("ok")
f.close()
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, [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('用户登录',"登录成功!")
else:
tk.messagebox.showinfo('用户登录',"登录失败!")
else:
tk.messagebox.showerror("用户登录",'邮件发送失败!')
else:
tk.messagebox.showerror('用户登录','您的输入不合法,请重新输入!')
if __name__ == '__main__':
checkmail(my_user)
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)
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)
try:
f=open("temp.txt")
if f.read()!='1':
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.账号或密码输入错误7次及以上就会永久锁定该账户,重新注册即可")
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")
f.close()
f = open("temp.txt", "w")
f.write("1")
f.close()
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.账号或密码输入错误7次及以上就会永久锁定该账户,重新注册即可")
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")
f=open("temp.txt","w")
f.write("1")
f.close()
win.mainloop()