脚本程序流程图:
#!/usr/bin/env python # _*_ coding:utf-8 _*_ #输入以上一行才可以识别中文字符注释# # ------------------------------------------------------------------------------- # FileName: login.py # Revision: 1.0 # Date: 2017/09/20 # Author: XAD # Email: [email protected] # Website: http://onenice.blog.51cto.com/ # Description: check login # Notes: ~ # ------------------------------------------------------------------------------- # Copyright: 2017(c)XAD # License: GPL import sys username = ‘xad‘ password = ‘xad123‘ retry_counter = 0 #login_status = ‘NO‘ login_status = ‘YES‘ #用这个来模拟用户是否已在线# # login verification part # while retry_counter <3 : #当retry_counter 大于3次则退出# user = raw_input(‘Username:‘).strip() if len(user) ==0: #验证输入用户是否为空,是则继续循环,否则进入下一步验证输入# print "ERROR : Username cannot be empty!" continue passwd = raw_input(‘Password:‘).strip() if len(passwd) == 0: #验证输入密码是否为空,是则继续循环,否则跳出循环# print "ERROR : Password cannot be empty!" continue else: if user == username and passwd == password: #验证用户密码是否都正确,都正确才允许登录!# if login_status == ‘YES‘: sys.exit(‘Sorry, user %s has been logining!‘ % user ) else: sys.exit(‘Welcome %s logining to system!‘ % user ) else: #retry_counter = retry_counter + 1 retry_counter += 1 print ‘Wrong username or password, please verify your username or password ! \nOnly %s more chances!‘ % (3 - retry_counter )
时间: 2024-10-09 18:07:35