# __author__ = Leo li
# !/usr/bin/env python
# -*- coding:utf-8 -*-
a = open("username.txt","r+")
x = open("password.txt","r+")
y = x.readlines()
b = a.readlines()
f = open("msg.txt","r+")
m = f.readlines()
counter = 0
cmd = 0
ax = 0
while cmd < 1:
a = open("username.txt","r+")
x = open("password.txt","r+")
y = x.readlines()
b = a.readlines()
print("欢迎来到Python论坛登陆界面")
print("1.注册用户")
print("2.登录用户")
print("3.退出")
chose = input("请输入你的选项:")
if chose == '1':
while chose:
user = input("请输入您要注册的用户名:")
if user+"\n" in b:
print("该用户名已存在,请重新输入")
else:
pwd = input("请输入您的密码:")
c = open("password.txt","a+")
c.write(pwd+"\n")
a = open("username.txt","a+")
a.write(user+"\n")
p = open("msg.txt","a+")
p.write("True\n")
p.close()
c.close()
a.close()
x.close()
print("注册成功!请重新运行登录程序!")
exit()
elif chose == '2':
while chose:
username = input("请输入您的用户名:")
password = input("请输入您的密码:")
d = open("username.txt",'r+')
if username+"\n" not in d:
print("您输入的用户名不存在,请重新输入")
d.close()
else:
q = open("msg.txt",'r+')
w = q.readlines()
e = b.index(username+"\n")
if w[e] == "True\n":
if counter <2:
if password+"\n" == y[e]:
print("登录成功!欢迎进入")
exit()
else:
print("你的密码错误,请重新输入")
counter+=1
continue
else:
g = open("msg.txt","w+")
m[e] = "False\n"
g.writelines(m)
g.close()
print("由于你尝试太多次,系统已锁定此账户,请联系管理员后重试")
print("正在退出程序…………")
exit()
else:
print("您好,由于你的密码输入错误次数过多,系统已锁定此账户,请联系管理员后重试")
print("正在返回登录界面……")
print("\n")
break
elif chose == '3':
print("正在退出……")
exit()
else:
print("您的输入有误,请输入您要选择的序号(“1”,“2”,“3”)")
转载于:https://blog.51cto.com/11793019/1867362