编写登陆接口:
- 输入用户名密码
- 认证成功后显示欢迎信息
- 输出3次后锁定
#!/usr/bin/env python
import sys
username = 'Luck'
password = 'Luck'
locked = 1
retry_counter = 0
while retry_counter <3 :
user = raw_input('Username:').strip()
if len(user) ==0:
print '\033[31;1m用户不能为空,请重新输入!\033[0m'
continue
passwd = raw_input('Password:').strip()
if len(passwd) == 0:
print '\033[31;1m密码错误!\033[0m'
continue
#handle the username and passwd empty issue
#going to the loging verification part
if locked == 0:#means the user is locekd
print 'Your username is locked!'
sys.exit()
else:
if user == username and passwd == password:
#means passed the verfification
sys.exit('Welcome %s login to our system!' % user )
else:
#retry_counter = retry_counter + 1
retry_counter += 1
print '\033[31;1mWrong username or password, you have %s more chances!\033[0m' % (3 - retry_counter )
\033[31; \033[0m