#用户输入用户名密码,如果在锁定文件中,则告知用户名已被锁定。 #如用户不在锁定文件中,匹配用户名和密码,如果验证成功打印欢迎介面 #如果匹配不成功,让用户重新输入,用户有三次机会,超过3次退出程序 #如果用户最后输入的用户名在系统用户文件中,则将其写入到锁定文件,反之则不写入锁定文件。 # 文件account.txt内容如下: # Jacky 1234 # sky 3356 # Yvone 5566 #account_lock.txt为空 cmd = input(''' 1:登录系统 2:即出系统 请选择: ''') if cmd.isdigit() and int(cmd) == 2: exit() elif cmd.isdigit() and int(cmd) == 1: pass else: print('您输入有误!') exit() i = 0 j = 0 while i < 3: user_input = input('Please input your username:') passwd_input = input('Please input your password:') list_lock = open('account_lock.txt', 'r+') lock_user = list_lock.readlines() for line in lock_user: lines = line.strip(' ') if lines == user_input: print('Username %s has been locked!' % user_input) exit() else: pass list_user = open('account.txt', 'r') user_info = list_user.readlines() for line in user_info: (username, password) = line.strip(' ').split() if username == user_input and password == passwd_input: print(''' 33[1;32m ************************************************* * WELCOME * ************************************************* 33[0m''') j = 3 break if j < 2: j += 1 print(' 33[1;31m Wrong username or password 33[0m') continue else: # 判断用户输入的用户名是否在系统的用户列表中,如果存在将用户名锁定,如果不存在则不加入锁定文件中。 for i in user_info: if j != 3 and user_input in i.strip(' ').split(): list_lock.write(user_input + ' ') i = 3 list_lock.close() list_user.close() print('contin')