python密码错误三次锁定(实例讲解)

作者:smelond 时间:2022-03-02 07:51:23 

程序需求:

输入用户名,密码

认证成功显示欢迎信息

输入错误三次后锁定用户

流程图:

好像画的不咋地

python密码错误三次锁定(实例讲解)

查看代码:


#!/usr/bin/env python
# _*_ coding:utf-8 _*_
# File_type:一个登录接口
# Author:smelond
import os

username = "smelond"#用户名
password = "qweqwe"#密码
counter = 0#计数器

#读取黑名单
file = os.path.exists("./user.txt")#检查当前目录是否有user.txt这个文件,如果有者输出True赋给file
if file == True:#判断是否有user.txt这个文件
blacklist_file = open("user.txt", "r").read()#open()打开文件,并且用read()读取文件,然后赋给blacklist_file
if blacklist_file == username:#检查文件里面的内容是否和我们的用户名相等
 print("Username lock. Please contact the administrator to remove the restrictions!!!")#输出错误提示
 exit()#退出程序

#登录接口
for i in range(3):
counter += 1#对每次登录进行计数
input_user = input("Please input username: ")
input_pass = input("Please input password: ")
if input_user == username and input_pass == password:
 print("Welcome login...")
 break
else:
 print("ERROR Incorrect username or password!!!")
 continue

#写入黑名单
if counter == 3:#判断我是否输入错误三次
print("The user name has been disabled")#提示信息
blacklist_user = open("user.txt", "a")#以追加模式打开 (从 EOF 开始, 必要时创建新文件)
blacklist_user.write("%s" % username)#将用户名写入黑名单
blacklist_user.close()#使用open后一定要记得调用文件对象的close()方法

来源:http://www.cnblogs.com/smelond/archive/2017/11/13/7828020.html

标签:python,密码错误,三次,锁定
0
投稿

猜你喜欢

  • ASP、PHP与javascript根据时段切换CSS皮肤的代码

    2008-09-01 17:26:00
  • PDO::prepare讲解

    2023-06-06 06:15:28
  • Python爬虫入门案例之爬取二手房源数据

    2021-07-13 15:31:41
  • Go语言sort包函数使用示例

    2023-10-15 03:29:59
  • Python详解argparse参数模块之命令行参数

    2021-06-20 21:16:18
  • 一个ASP站内搜索的实例源代码

    2007-09-21 12:13:00
  • php生成随机密码的三种方法小结

    2023-11-22 04:25:50
  • asp 多关键词搜索的简单实现方法

    2011-04-11 10:45:00
  • python opencv实现信用卡的数字识别

    2023-07-05 02:20:23
  • python实现根据窗口标题调用窗口的方法

    2022-06-12 04:24:40
  • sqlserver 索引的一些总结

    2012-08-21 11:03:31
  • 在SQL Server中使用索引的技巧

    2009-02-24 17:50:00
  • IE下中英文字体不能对齐原因及解决

    2008-08-11 12:47:00
  • 跨浏览器的本地存储(一):userData behavior

    2008-08-05 18:13:00
  • Python安装第三方库攻略(pip和Anaconda)

    2023-02-01 22:16:41
  • 快速配置PHPMyAdmin方法

    2023-07-16 07:05:20
  • js验证表单(form)中的单选(radio)值

    2008-03-18 13:23:00
  • 关于 Flash Banner 设计的建议

    2010-02-02 18:19:00
  • python接口测试对修改密码接口进行压测

    2022-05-16 04:26:15
  • asp xmlhttp下载一句话

    2013-06-30 06:47:48
  • asp之家 网络编程 m.aspxhome.com