一、脚本功能
登录接口
-输入用户名、密码
-用户名、密码为空,提示
-输错三次锁定
-认证成功后,显示欢迎登录信息
二、流程图
三、python代码
[[email protected] Day1]# cat login.py
#!/usr/bin/env python
import sys
username = ‘hanyun‘
password = ‘hanyun123‘
retry_count = 0
while True:
user = raw_input(‘Username:‘).strip()
if len(user) == 0:
print ‘Username cannot be empty!‘
continue
passwd = raw_input(‘Password:‘).strip()
if len(passwd) == 0:
print ‘Password cannot be empty!‘
continue
#handle the username and passwd empty issue
#going to the loging verificaiton part
if user == username and passwd == password:
print ‘welcome %s login our system!‘ % user
break
else:
retry_count += 1
print ‘Wrong username or password,you have %s more chances!‘ % (3 - retry_count)
if retry_count == 3:
print ‘Your username is locked!‘
sys.exit()
四、功能演示
[[email protected] Day1]# python login.py
Username:fdsaf
Password:cdsaf
Wrong username or password,you have 2 more chances!
Username:ada
Password:cdfd
Wrong username or password,you have 1 more chances!
Username:adfsa
Password:333
Wrong username or password,you have 0 more chances!
Your username is locked!
[[email protected] Day1]# python login.py
Username:afc
Password:123
Wrong username or password,you have 2 more chances!
Username:hanyun
Password:hanyun123
welcome hanyun login our system!
[[email protected] Day1]# python login.py
Username:
Username cannot be empty!
Username:fdsfa
Password:dsf
Wrong username or password,you have 2 more chances!
Username:aa
Password:
Password cannot be empty!
Username: