首页 > 代码库 > python作业:编写登陆接口
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!")
python作业:编写登陆接口
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。