编写登陆接口
- 输入用户名密码
- 认证成功后显示欢迎信息
- 输错三次后锁定
#!/usr/bin/env python # _*_ coding:utf8 _*_ import getpass Username = 'daxin' Password = '123456' def panduan(name): with open('/tmp/result.log') as fd: content = fd.read() if len(content) == 0: return True else: lockname = content.split()[0] zhuangtai = content.split()[1] if lockname == name and zhuangtai == 'lock': return False else: return True count = 0 while count < 3: username = raw_input('login:') password = getpass.getpass('password:') result = panduan(username) if result: if username == Username and password == Password: print "欢迎登陆" break elif username != Username: print "用户名不存在!,请注册!" break else: print '用户名/密码错误' break count += 1 else: print '帐号已经锁定!' break else: print '帐号已经锁定!' with open('/tmp/result.log','r+') as fd: fd.write('daxin lock')