import sys count=0 while count<3: user = input("Please enter user name:") lock_file = open(‘D:\\lock.txt‘, ‘r+‘) lock_list = lock_file.readlines() for lock_line in lock_list: lock_line = lock_line.strip(‘\n‘) if user == lock_line: print(‘The user has been locked‘) sys.exit() user_file = open("D:\\username.txt", ‘r‘) user_list = user_file.readlines() for user_line in user_list: name, pwd = user_line.strip(‘\n‘).split() if user == name: count_1 = 0 while count_1 < 3: password = input(‘Please enter user password:‘) if password == pwd: print(‘%s welcome!‘ % user) sys.exit() else: print(‘Password error‘) count_1 += 1 if count_1 == 3: print(‘The password has been entered many times. The user has been locked‘) lock_file.write(user) sys.exit() else: pass else: if count != 2: print(‘The username does not exist‘) count += 1 else: print(‘The username has been entered many times‘) sys.exit()
时间: 2024-11-05 23:12:39