-
#_*_ coding:utf-8 _*_
-
import os, sys
-
if os.path.isfile('user.txt'):
-
pass
-
else:
-
sys.exit("\033[31m没有定义用户文件\033[0m")
-
user_li = []
-
with open('user.txt') as f1:
-
for i in f1:
-
user = i.strip('\n').split(':')
-
user_li.append(user)
-
#print(user_li)
-
-
def user_name(): #用户名列表
-
user_n = []
-
for name in user_li:
-
user_n.append(name[0])
-
return user_n
-
-
def user_passwd(): #密码列表
-
user_pass = []
-
for passwd in user_li:
-
user_pass.append(passwd[1])
-
return user_pass
-
-
if __name__ == '__main__':
-
while True:
-
user_na = input('请输入用户名:')
-
username = user_na.strip()
-
password = input('请输入密码:')
-
# password = input('请输入密码:')
-
if username in user_name():
-
location = user_name().index(username)
-
while int(user_li[location][2]) < 3:
-
if password == user_li[location][1]:
-
print ("\033[32m登录成功\033[0m")
-
sys.exit(0)
-
else:
-
location = user_name().index(username)
-
user_li.insert(location,[username,user_li[location][1],str(int(user_li[location][2])+1)])
-
user_li.pop(location+1)
-
# print(user_li)
-
with open('user.txt','w+') as f1:
-
for i in user_li:
-
s1 = ':'.join(i)
-
f1.write(s1+'\n')
-
print ("\033[31m账户名或密码错误\033[0m")
-
break
-
else:
-
print ("\033[31m账户已经锁定,请联系管理员!\033[0m")
-
sys.exit(0)
-
else:
-
print ("\033[31m账户名或密码错误\033[0m")
-
else:
-
print ("go out")
cat user.txt
yn:yn123:0
tom:123456:0