这是一个登入窗口,会判断用户名和密码是否正确,密码输入3次错误后,把该用户添加到blacklist,不允许登入。
#!/usr/bin/env python #-*- coding:utf-8 -*- # Li Rong Yang """ This is the login code. """ user_name = open("E:\python学习视频\username.txt") #读取用户名数据文件 name = user_name.read() _name = name.split(",")#把数据文件中字符串转为列表 password = open("E:\python学习视频\password.txt")#读取密码数据文件 _pass = password.read() _passs =_pass.split(",")#把数据文件中字符串转为列表 blacklist = open("E:\python学习视频\blacklist.txt")#读取黑名单数据文件 blacklistfile = password.read() count = 0 while True: if count == 3: break user_input = input("Please enter a user name: ")#提示用户输入登入名 if user_input in blacklist: #判断用户输入的登入名是否在黑名单中 print("You are on the blacklist, Please contact the Administrator.") break if user_input in _name:#判断用户输入的登入名是否在白名单中 for i in range(3): count += 1 mi = input("Please enter a user password.")#提醒用户输入密码 if mi in _passs:#判断用户输入的密码是否在密码数据文件中 print("Welcome {_name}".format(_name = user_input)) exit() else: print("Password error!!!") if count == 3: write_blacklist = open("E:\python学习视频\blacklist.txt",'a')#密码输入错误3次后,把该用户拉入黑名单 write_blacklist.write(user_input + ',') print("Password error 3 tiems,Please contact the Administrator.") else: print("Username error!!!")