python实现用户名密码校验
作者:s0cket 时间:2022-12-14 07:48:33
本文实例为大家分享了python实现用户名密码校验的具体代码,供大家参考,具体内容如下
需要实现功能
输入用户名密码 ;
认证成功后显示 欢迎信息 ;
连续输错三次后 锁定 ;
readme:
具体请看代码注释,懒了
1、输入用户名密码
2、判断用户名是否在锁定文件中
3、判断用户名密码是否正确
代码
# 输入用户名密码
# 认证成功后显示欢迎信息
# 连续输错三次后锁定
count = 0
while True:
#输入用户名密码
username = input("Username:")
password = input("Password:")
#打开用户名密码文件
f = open('login_true.txt')
#打开锁定用户名文件
f4 = open('login_lock.txt')
#判断输入用户名是否存在于锁定文件中
for line in f4:
user_name2 = line.strip()
if username == user_name2:
print("username is locked!")
break
else:
#判断用户名密码是否正确
for line in f:
str = line.strip()
str2 = ','
user_name = str[:str.index(str2)]
pass_word = str[str.index(str2)+1:]
# print(user_name, pass_word)
#用户名密码均正确,打印欢迎信息并清空计数器跳出循环
if username == user_name and password == pass_word:
print("welcome " + username)
count = 0
break
#用户名正确,密码错误,打印提示信息,计数器加1,并判断计数器是否到3
elif username == user_name and password != pass_word:
print("wrong password!")
count += 1
print(count)
#计数器到达3次,将用户名写入锁定文件中
if count == 3:
f2 = open('login_lock.txt', "a+")
f2.write(username+'\n')
f2.close()
count = 0
break
else:
print("please check out your username!")
count = 0
f.close()
注意
py文件同一目录下新建两个文件:
login_true.txt ---------事先存放好用户名密码
login_lock.txt----------用于存放锁定的用户名
来源:https://blog.csdn.net/s0cket/article/details/100581962
标签:python,密码校验
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python语音合成的项目实战(PyQt5+pyttsx3)
2021-06-15 09:14:13
![](https://img.aspxhome.com/file/2023/9/128549_0s.jpg)
Mysql错误1366 - Incorrect integer value解决方法
2024-01-13 03:21:35
Keras中的多分类损失函数用法categorical_crossentropy
2023-06-23 12:25:37
![](https://img.aspxhome.com/file/2023/5/63935_0s.jpg)
记一次Django响应超慢的解决过程
2021-11-23 13:35:57
通用的二级菜单代码(css+javascript)
2024-06-09 18:35:28
详解Python图像处理库Pillow常用使用方法
2022-07-17 11:04:53
python中合并两个文本文件并按照姓名首字母排序的例子
2023-05-28 17:41:32
go语言实现二叉树的序例化与反序列化
2024-04-26 17:27:30
![](https://img.aspxhome.com/file/2023/2/134082_0s.webp)
在ASP.NET 2.0中操作数据之二十三:基于用户对修改数据进行限制
2023-07-12 08:52:20
![](https://img.aspxhome.com/file/2023/4/75524_0s.png)
Python3 socket即时通讯脚本实现代码实例(threading多线程)
2022-05-20 08:52:17
Oracle复合索引与空值的索引使用问题小结
2024-01-21 17:35:38
![](https://img.aspxhome.com/file/2023/2/65692_0s.png)
Pycharm及python安装详细步骤及PyCharm配置整理(推荐)
2021-03-15 21:55:51
![](https://img.aspxhome.com/file/2023/9/76019_0s.jpg)
jQuery选择器用法实例详解
2024-04-09 19:48:41
asp如何用WSH获取机器的IP配置信息?
2010-06-13 14:39:00
php上传大文件设置方法
2023-11-21 19:11:22
mysql通过文档读取并执行命令之快速为mysql添加多用户和数据库技巧
2024-01-24 01:45:02
Python OrderedDict字典排序方法详解
2022-01-07 13:32:09
js获取地址栏中传递的参数(两种方法)
2024-04-17 09:54:30
对PyQt5基本窗口控件 QMainWindow的使用详解
2021-08-27 21:47:22
![](https://img.aspxhome.com/file/2023/8/90468_0s.jpg)
一次性压缩Sqlserver2005中所有库日志的存储过程
2024-01-28 13:40:13