#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:Dejun Kong
import getpass
import sys

count = 0
username = input("username:")
with open('d:\Black_list.txt','r') as r:
    data = r.readlines()
    for i in data:
        if i.strip('\n') == username:   #i.strip('\n')，去除i数值后面的\n格式
            print("your username is block!!,Please retry again!")
            break
            #sys.exit(0)
    else:
        while count < 3: #定义循环次数，密码出错地方循环3次。
            password = input("password:")
            with open('d:\login.txt','r') as l:
                login_info = l.readlines()

                for pwd in  login_info:
                        a=pwd.strip('\n').split(':')  #过滤回车，并且用split来切片，':'符号为间隔符
                        #if a[1] == password:
                          #  print(a[1])    #打印a[1] 密码文件
                        if a[0] == username and a[1] == password:
                            #print(a[0])    #打印a[0]用户名
                            print("welcome login")
                            break
                else:
                    print("Invalid Password")
                    count +=1
                    if count == 3 :
                        print("your account is lock...")

                        with open('d:\Black_list.txt','a') as a:    #使用a.write追加写入指定文件
                            a.write(username + '\n')    #文件格式：记录用户名和换行键 每次追加都会换一行
