首页 > 代码库 > day1-用户登录接口程序

day1-用户登录接口程序

代码:

技术分享
 1 yuying0117
 2 day1--login.py
 3 
 4 # !/usr/bin/env python
 5 # -*- coding: utf-8 -*-
 6 #Author Yuying  
 7 #读取工号信息
 8 staff_data =http://www.mamicode.com/ {}
 9 with open(staff_list, r) as df:
10     for kv in [d.strip().split( ) for d in df]:
11         staff_data[kv[0]] = kv[1]
12 #print(staff_data)
13 #读取黑名单工号信息
14 blacklist = []
15 with open(staff_blacklist, r) as df:
16     for rd in df.readlines():
17         blacklist.append(rd.strip(\n))
18 #print (blacklist)
19 log_num = 0
20 while True:
21     staff_name = input("name:")
22     staff_password = input("password:")
23     if not ( staff_name in staff_data):
24         print("该工号不存在")
25         continue
26     elif ( staff_name in blacklist):
27         print("该工号已经被锁定!")
28         continue
29     elif(staff_password != staff_data.get(staff_name)):
30         log_num = log_num + 1
31         print("密码错误,第" + str(log_num) + "次!")
32         if(log_num == 3):
33             #错误超过三次,把工号写入staff_blacklist
34             f = open(staff_blacklist,a)
35             f.write(staff_name+\n)
36             f.close()
37             print("错误超过三次,工号被锁定")
38             break
39     else:
40         print("登录成功!")
41         break
View Code

 工号文件:

技术分享
1 lilei abc123
2 hanmeimei abc1234
3 lucy abc12345
4 lily abc123456
staff_list

黑名单文件:

技术分享
1 lucy
staff_blacklist

day1-用户登录接口程序