1 #!/usr/bin/env python
 2 import sys
 3 import getpass
 4 afile = 'afile'
 5 bfile = 'bfile'
 6 circulation_num=0  #循环次数初始基数
 7 def deny_account(username):
 8         print("This account already locked!")
 9         with open(bfile, 'a+') as bf:     #此处最好为a+模式,本人之前使用a模式错误账号无法写入
10             bf.write(username + '\n')
11 #循环开始
12 while circulation_num<3:
13         username = input("\033[32;1mPlease input your username:\033[0m")
14         flag = False
15         with open(afile, 'r') as af:
16                 for line in af.readlines():
17                         user,pwd=line.strip().split()
18                         if username==user:
19                                 password=getpass._raw_input('Please input password:').strip()
20                                 if username==user and password ==pwd:
21                                     print('success!')
22                                     flag = True
23                                     break
24                                 else:
25                                      print('password error,please try again!')
26                         else:
27                             if circulation_num < 3:
28                               print('User doesn`t exist!')
29                               circulation_num += 1
30                         break
31         if flag == True:
32                 print('Welcome %s come in TG!' % username)
33                 break
34 else:
35     deny_account(username)

 afile内容:

carl openstack

helen tellme

lucy tianle

linken is3333

bfile内容随意

 

posted on 2016-04-16 21:55  geek3  阅读(216)  评论(0编辑  收藏  举报