Python模拟用户登录

#!/usr/bin/python

#_*_ coding:utf-8 _*_
#Author:moshell
#datetime:2018/6/11 9:28

import sys


f1=open(r'Account_Password.txt','r')
f2=open(r'Lock_Account.txt','r')
Info={}
Lock=[]
for line in f1:
k,v=line.strip().split()
Info[k]=v
for line in f2:
Lock.append(line.strip())
f1.close()
f2.close()
f3=open(r'Lock_Account.txt','a')

Flag=True
while Flag:
User = input('\033[33;1m请输入用户名:\033[0m').strip()
if len(User)>0:
if User in Lock:
print('您输入的账户已锁定,请联系管理员.')
sys.exit()
elif User in Info.keys():
count=0
while count < 3:
Pwd=input('\033[33;1m请输入密码:\033[0m').strip()
if len(Pwd) > 0:
if Pwd == Info[User]:
print('%s,欢迎登陆此系统.'%User)
sys.exit()
else:
print('密码错误,请重新输入.')
else:
print('\033[36;1m您输入的密码为空.\033[36;0m')
count+=1
else:
Err_info=User+'\n'
f3.write(Err_info)
print('账户已经被锁定,如有疑问,请联系管理员')
Flag=False
else:
print('用户名不存在,请重新输入.')
else:
print('您输入的用户名为空,请重新输入用户名.')
continue
f3.close()


猜你喜欢

转载自www.cnblogs.com/moshell/p/9166413.html