#!/usr/bin/env python
#auther = shaw
#ver = 1.3
import startup
account = {}
acclist = []
#产生账号信息字典
with open('accountlist.txt','r+') as acc: #accountlist.txt文件事先已被编写好,一行用户名,一行密码
for i in acc.readlines():
acclist.append(i.strip('\n'))
for i in range(0,len(acclist),2):
name = acclist[i]
passwd = acclist[i+1]
account[name] = passwd
i = 0
status = False
#判断主体
while i <= 2:
name = raw_input('Please input your name:').strip()
with open('lock.txt','r+') as acclock: # 判断账号是否被锁定begin
for f in acclock.readlines():
if name == f.strip('\n'):
print '\033[31;2mSorry.you account has been locked.\033[0m'
status = True
break
if status is True:break # 判断账号是否被锁定end
passwd = raw_input('Please input your passwd:').strip()
if account.has_key(name) and account[name] == passwd: # 判断用户是否存在,以及此用户密码是否正确
print '### \033[32;2mLogin Succsss\033[0m.'
break
else:
i = i + 1
print '### \033[33;2myour name or passwd wrong\033[0m...'
continue
# 用户名密码输入错误3次,锁定账号
if i > 2:
print '\033[31;2mSorry.you account has been locked.\033[0m'
lock = file('lock.txt','a')
lock.write('%s\n'% name)
lock.close()
转载于:https://my.oschina.net/u/2428313/blog/486823