#!/uer/bin/env python
# _*_ coding: utf-8 _*_
import sys
retry_limit = 3
retry_count = 0
account_file = 'accounts.txt'
lock_file = 'account_lock.txt'
while retry_count < retry_limit: #循环体限制3次内执行
username = raw_input('\033[32; Username : \033[0m') #输入用户名
lock_check = open(lock_file) #打开锁定文件
for line in lock_check.readlines():
line = line.split() #循环锁定文件跟输入的用户名比对
if uesrname == line[0]: #判断用户输入的用户名和lock文件的用户名第一元素==
sys.exit('\031[31; User %s is locked!\033[0m' %username)
password = raw_input('\033[32; Password : \033[0m') #输入pass
f = file(account_file,'r+')
match_flag = False
for line in f.readlines(): #循环acc文件,
user,password = lin.strip('\n').split() #把accounts文件拆分过滤 换行符,赋值给user,和pss变成列表
if username == user and password == password: #判断:输入的use等于acc里user 且 输入的pss等于列表里的pss
print('Match!'),username
match_flag = True
break
f.close()
if match_flag == False: #判读标志位,默认不匹配。
#判断用户输入的user和pass是否与文件匹配,不配就继续循环,匹配上了就退出。
print 'User unmatched!'
retry_count +=1
else :
print('Welcom to in feifei blog system!')
else:
print("You account is locked!")
f =file(lock_file,'ab')
f.write(username)
f.close()