1 # -*- coding: utf-8 -*- 2 ‘‘‘ 3 -------------------------------------------- 4 已有功能:输入用户名密码;认证成功后显示欢迎信息;输错三次后永久锁定 5 待以后添加:定时解锁;使用数据库等大量存储用户并调用 6 -------------------------------------------- 7 ‘‘‘ 8 username = ‘AAA‘ 9 password = ‘aaa‘ 10 11 def userLock(): 12 try_times = 0 13 while try_times < 3: 14 usernameInput = input(‘用户名:‘) 15 if usernameInput == username: 16 with open(‘userLock‘,‘r‘,encoding=‘utf-8‘) as userLock_file: 17 if usernameInput in userLock_file: 18 print("用户%s已被锁定,请联系客服(客服电话:10086)!" % usernameInput) 19 return 0 20 else: 21 times = 0 22 while times < 3: 23 passwordInput = input(‘密 码:‘) 24 if passwordInput == password: 25 print("%s,感谢您的登录!\n\t欢迎!" % username) 26 return 0 27 else: 28 print("密码输入错误!请重新输入!") 29 times += 1 30 else: 31 with open(‘userLock‘,‘r+‘,encoding=‘utf-8‘) as fileUserLock: 32 fileUserLock.write(usernameInput) 33 print("用户已锁定,请联系客服(客服电话:10086)!") 34 return 0 35 else: 36 print("无效的用户名!") 37 try_times += 1 38 39 40 userLock()