Python3源码_账号密码输入接口
Posted SKING_Python
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python3源码_账号密码输入接口相关的知识,希望对你有一定的参考价值。
1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 #Author:SKING 4 """ 5 题目: 6 输入账号,密码 7 1.输入三次后提示休息5s 8 2.密码重复输入三次后锁定账户 9 """ 10 11 import string, sys, time 12 13 def wait_5s(): 14 print(‘You input too many times,please wait 5s...‘) 15 for a in range(5, 1, -1): 16 print(f‘{a}s‘) 17 time.sleep(1) 18 19 count = 0 #记录用户输入的次数 20 count_pwd = 3 #记录用户输入密码的次数 21 22 while count<3: 23 count +=1 24 username = input(‘username:‘) 25 if username == ‘‘: 26 print(‘用户名不能为空!请重新输入!‘) 27 if count == 3: 28 wait_5s() 29 count = 0 30 continue 31 32 with open(‘locked_user.txt‘, ‘r‘, encoding=‘utf-8‘) as file_locked_user: 33 for i in file_locked_user: 34 i = i.strip() 35 if username == i: 36 print(f‘{username} is locked!‘) 37 chose_key = input(‘Press "Q" to exit!Press any key to continue:‘) 38 if chose_key == ‘Q‘ or chose_key == ‘q‘: 39 sys.exit(0) 40 with open(‘user_password.txt‘, ‘r‘, encoding=‘utf-8‘) as file_user_password: 41 for j in file_user_password: 42 (file_username, file_password) = j.strip().split(‘ ‘) 43 if username == file_username: 44 while count_pwd > 0: 45 print(f‘You have {count_pwd} times,then will locked!‘) 46 password = input(‘password:‘) 47 if password == file_password: 48 print(‘Welcome to Python!‘) 49 sys.exit(0) 50 else: 51 print(‘Password is wrong,Please re-enter...‘) 52 count_pwd -= 1 53 if count_pwd == 0: 54 with open(‘locked_user.txt‘, ‘r+‘, encoding=‘utf-8‘) as write_locked_user: 55 write_locked_user.write(username) 56 print(f‘{username} is locked!‘) 57 sys.exit(0) 58 else: 59 print(f‘{username} is not exist,Please re-enter...‘) 60 61 if count == 3: 62 wait_5s() 63 count = 0
以上是关于Python3源码_账号密码输入接口的主要内容,如果未能解决你的问题,请参考以下文章
wxPython:当密码账号输入正确,登录界面消失并显示主界面
wxPython:当密码账号输入正确,登录界面消失并显示主界面