python作业:编写登陆接口

python作业:编写登陆接口

要求:

1.要求用户输入用户名和密码

2.认证成功显示欢迎信息

3.输入错误超过三次锁定用户

 

 1 #!/usr/bin/env python
 2 #_*_coding:utf-8_*_
 3 #__author__ = 'Administrator'
 4 
 5 static=True
 6 login=False
 7 username=''
 8 lockfile=r'lock.txt'
 9 for i in range(3):
10     username=input("please input your username:")
11     password=input("please input your password:")
12 
13     
14     with open(lockfile,'r') as lockobject:
15          users=lockobject.readlines()
16          for line2 in users:
17              line2=line2.strip('\n')
18 
19              if line2 == username:
20                  static=False
21                  break
22 
23     if static==False:
24         break
25 
26 
27     with open(r'user.txt','r') as user:
28          users=user.readlines()
29     for line in users:
30         userinfo="|".join([username,password])
31         line=line.strip('\n')
32         if userinfo == line:
33             print('welcome {username} !'.format(username=username))
34             login=True
35             break
36 
37     if login:
38         break
39     else:
40          print('Invalid username and password!\n')
41 
42 if login==False:
43     if static:
44         with open(lockfile,'a') as lockobject:
45              line_string=''.join([username,'\n'])
46              lockobject.write(line_string)
47     print("lock!")

 

posted @ 2017-02-12 20:18  alston-lee  阅读(183)  评论(0编辑  收藏  举报