Python实战之实现简单的登陆系统-作业
#!usr/bin/env Python3 # -*-coding:utf-8-*-
#编写登陆接口
#输入用户名密码
#认证成功后显示欢迎信息
#输错三次后锁定
__author__="William" #定义一个login类 class Login(object): count = 3 Flag = 1 wrong_user_flag = 1 wrong_user = ''
#定义一个静态方法,用于主函数调用 @staticmethod def login(): while Login.count > 0: if Login.wrong_user_flag == 0: username = Login.wrong_user else: username = input("Please input your username:>>>") Login.wrong_user = username password = input("Please input your password:>>>") Login.verify(username,password) Login.count -= 1 else: if Login.Flag != 1: with open("black_user.txt",'a') as fp: fp.write("\n") fp.write(username) fp.write("\n") @staticmethod def verify(user_name,password): with open("black_user.txt", 'r') as fp: data = ''.join(fp.readlines()).split('\n') if user_name in data: print("Your are locked") Login.count = 0 else: if user_name == "William" and password =="123": print("Success,welcome to login") Login.Flag = 1 Login.count = 0 else: print("Wrong username or password") Login.Flag = 0 Login.wrong_user_flag = 0 if __name__=='__main__': u1 = Login() u1.login()
posted on 2017-07-02 10:24 William126 阅读(252) 评论(0) 编辑 收藏 举报