作业内容:
pass
流程图:
代码:
1、主文件
1 import sys 2 3 lock = "lock.txt" 4 logfile = "login.txt" 5 login_info = 0 6 i = 0 7 8 while i < 3 and login_info== 0 : 9 name = input("Please input your name: ") 10 11 f = open(lock, "r") 12 for line in f.readlines(): 13 # if name in line: 14 if name == line.strip(): 15 f.close() 16 sys.exit(‘\033[32:1m用户 %s 已经被锁定\033[0m‘ % name) 17 18 password = input("Please input password: ") 19 20 f = open(logfile, "r") 21 for line in f.readlines(): 22 user_file, pass_file = line.split() 23 if user_file == name and pass_file == password: 24 print("Bingo!") 25 login_info = 1 26 break 27 else: 28 print("You name or password is errer!") 29 i += 1 30 f.close() 31 else: 32 if i == 3 and login_info == 0: 33 f = open(lock, "a") 34 f.write(name + "\n") 35 f.close() 36 print(‘\033[32:1m用户 %s 已经被锁定\033[0m‘ % name)
2、系统用户帐号密码信息
1 root rootgm 2 gm 12345 3 hlr hlr123
3、当前系统被锁用户信息
gm
测试结果:
1、测试锁定用户能否登录系统
2、测试登录3次能否登录
3、测试登录1次能否登录
4、测试登录3次失败后,是否会锁定帐号
时间: 2024-10-08 13:33:27