1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| accounts = {} f1 = open('user.db', 'r') for line in f1: line = line.strip().split(',') accounts[line[0]] = line
while True: user = input('username:').strip() if user not in accounts: print('该用户未注册...') continue elif accounts[user][2] == '1': print('该用户已被锁定,请联系管理员...') continue count = 0 while count < 3: passwd = input('password:'.strip()) if passwd == accounts[user][1]: print(f'Welcome {user}!') exit('bye...') else: print('Wrong password, please try again...') count += 1 if count == 3: print(f'输错了{count}次密码,用户{user}将被锁定...') accounts[user][2] = '1' f2 = open('user.db', 'w') for user, val in accounts.items(): line = ','.join(val) + '\n' f2.write(line) f2.close() exit('bye...')
|