详解Python用户登录接口的方法
作者:qiyue0087 时间:2021-10-09 23:26:48
Readme:
blog address:
摘要:编写登录接口
输入用户名、密码
认证成功后显示欢迎信息
输错3次后锁定
关键词:循环;判断;外部数据读写;列表;字典;
展望:可以结合数据库读写。
codes:
# Author: Steven Zeng
'''
作业2:编写登录接口
输入用户名密码
认证成功后显示欢迎信息
输错3次后锁定
'''
print("welcome to here")
f1=open('username.txt')
f2=open('password.txt')
f3=open('error.txt')#建立一个Demo记录输错3次密码的用户,并对其锁定
username_true=f1.readlines()#readlines读取方式返回的是逐行一个元素的列表
password_true=f2.readlines()
un_error=f3.readlines()
f1.close()
f2.close()
f3.close()
UK={}
#建立一个字典形式为用户名对密码
for i in range(len(username_true)):
UK[str(username_true[i])]=str(password_true[i])#注:字典的键必须是不可变更型数据(常用整数和字符串)
# 而键值可以是数字也可以是字符串
#print(un_error)
#print(un_error.count(777+'\n')
#print(UK)
count=0
while count<3:
username = input("Please, input your username:")
password = input("Please, input your keywords")
if un_error.count(str(username+'\n'))>=3:
print("Out of trying, You are Locking!")
break
elif str(username+'\n') in UK and str(password+'\n')==UK.get(str(username+'\n')):
print("welcome to you, honorable customer!")
break
else:
print('''Invalid customer, please try again!
And you have {count_left1} times left!'''.format(count_left1=2-count))
f3=open('error.txt','a')#建立一个Demo记录输错3次密码的用户,并对其锁定
f3.write(username+'\n')
f3.close()
count += 1
以上所述是小编给大家介绍的Python用户登录接口的方法详解整合网站的支持!
来源:https://blog.csdn.net/qiyue0087/article/details/89192102
标签:Python,用户登录,接口
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python中and和or如何使用
2022-04-27 18:01:49
JS不同加载方式下的window.onload
2009-05-21 18:09:00
![](https://img.aspxhome.com/file/UploadPic/20095/21/j200951902925-22s.gif)
keras回调函数的使用
2022-08-22 11:42:41
![](https://img.aspxhome.com/file/2023/1/92401_0s.png)
python 用opencv实现图像修复和图像金字塔
2022-09-27 09:24:22
![](https://img.aspxhome.com/file/2023/9/83929_0s.png)
Python实现调用另一个路径下py文件中的函数方法总结
2021-05-24 12:48:03
![](https://img.aspxhome.com/file/2023/1/67271_0s.png)
python读取当前目录下的CSV文件数据
2022-04-06 16:50:35
![](https://img.aspxhome.com/file/2023/6/87496_0s.jpg)
基于Python-turtle库绘制路飞的草帽骷髅旗、美国队长的盾牌、高达的源码
2023-04-28 19:03:53
![](https://img.aspxhome.com/file/2023/2/71572_0s.gif)
Python多进程之进程同步及通信详解
2022-01-07 00:29:13
![](https://img.aspxhome.com/file/2023/9/71299_0s.png)
web标准知识——美化段落文本 Ⅱ
2008-07-22 12:12:00
《用户体验的要素》摘记
2008-08-04 17:59:00
关于点击区域
2009-07-24 13:08:00
![](https://img.aspxhome.com/file/UploadPic/20097/24/3734741624_d711acb9a5-35s.jpg)
Python heapq库案例详解
2022-12-27 12:26:52
![](https://img.aspxhome.com/file/2023/4/89444_0s.png)
asp中设置session过期时间方法总结
2013-06-01 19:52:04
Python装饰器如何实现修复过程解析
2023-11-22 04:27:43
![](https://img.aspxhome.com/file/2023/3/65953_0s.png)
Python读取xlsx数据生成图标代码实例
2022-01-11 11:35:56
![](https://img.aspxhome.com/file/2023/3/69023_0s.png)
该用多大的字
2009-05-17 14:39:00
php中对象引用和复制实例分析
2023-10-20 23:05:02
python单例模式实例分析
2021-11-02 12:17:49
给网站界面预留退路
2009-03-25 20:32:00
![](https://img.aspxhome.com/file/UploadPic/20093/25/01-11s.jpg)
Python中使用items()方法返回字典元素对的教程
2023-11-20 13:07:09