博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python3源码_账号密码输入接口
阅读量:4501 次
发布时间:2019-06-08

本文共 2534 字,大约阅读时间需要 8 分钟。

流程图:  1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 #Author:SKING 4 """ 5 题目: 6 输入账号,密码 7 1.输入三次后提示休息5s 8 2.密码重复输入三次后锁定账户 9 说明:10 locked_user.txt  存储锁定的账号   初始内容为空11 user_password.txt  存储用户名和密码  用户名和密码中间用'\t'制表符间隔12 """13 14 import string, sys, time15 16 def wait_5s():  #等待5秒的函数17     print('You input too many times,please wait 5s...')18     for a in range(5, 1, -1):19         print(f'{a}s')20         time.sleep(1)21 22 count = 0 #记录用户输入的次数23 count_pwd = 3 #记录用户输入密码的次数24 25 while count<3: #超过三次调用休息5s函数26     count +=127     username = input('username:') #输入用户名28     if username == '':29         print('用户名不能为空!请重新输入!')30         if count == 3:31             wait_5s() #超过三次调用休息5s函数32             count = 033         continue34     #打开'locked_user.txt'文件35     with open('locked_user.txt', 'r', encoding='utf-8') as file_locked_user:36         for i in file_locked_user: #循环读取file_locked_user37             i = i.strip() #去除i中的空格 换行等38             if username == i:39                 print(f'{username} is locked!')40                 chose_key = input('Press "Q" to exit!Press any key to continue:')41                 if chose_key == 'Q' or chose_key == 'q':42                     sys.exit(0)43     # 打开'user_password.txt'文件44     with open('user_password.txt', 'r', encoding='utf-8') as file_user_password:45         for j in file_user_password:46             (file_username, file_password) = j.strip().split('\t') #提取用户名、密码47             if username == file_username:48                 while count_pwd > 0:49                     print(f'You have {count_pwd} times,then will locked!')50                     password = input('password:')51                     if password == file_password:52                         print('Welcome to Python!') #账号、密码正确登录系统53                         sys.exit(0)54                     else:55                         print('Password is wrong,Please re-enter...')56                         count_pwd -= 157                     if count_pwd == 0: #输错三次密码,账号就没锁定58                         #打开'locked_user.txt'文件并写入要锁定的账号59                         with open('locked_user.txt', 'r+', encoding='utf-8') as write_locked_user:60                             write_locked_user.write(username)61                         print(f'{username} is locked!')62                         sys.exit(0)63         else:64             print(f'{username} is not exist,Please re-enter...')65 66     if count == 3: #如果输入超过三次就等待5s67         wait_5s()68         count = 0

 

转载于:https://www.cnblogs.com/skings/p/10213441.html

你可能感兴趣的文章
Ext JS - Ext.grid.feature.Grouping 分组表格
查看>>
ZConfig手册
查看>>
linux用户和用户组管理详解
查看>>
Jmeter之集合点
查看>>
JavaScript 基础,登录前端验证
查看>>
SQLite帮助类SQlitehelper 实现对SQLite数据的增删改查
查看>>
【转】字符、字符数组、char、string的区别分析
查看>>
HDU-3660 Alice and Bob's Trip 树形dp
查看>>
OpenLayers 搭建跨域代理(WFS)
查看>>
关于cros解决跨域的一个小例子(判断IP地址选择加不加跨域)
查看>>
图画hadoop -- 入门学习路线
查看>>
C#整理2——C#的输入输出及基本类型
查看>>
递归方法求解Fibonacci数列
查看>>
事件处理
查看>>
vue编辑回显问题
查看>>
我在博客园安家了
查看>>
SQL SERVER 数据库日期算法总结
查看>>
PHP 中文字符串相关
查看>>
开始搭建 myBatis.net + Spring.net + asp.net mvc 3 + easyUI 开发平台
查看>>
vue-cli的项目中关于axios的全局配置
查看>>