用python的列表和if判断,简单写的一个用户登录接口程序
流程图如下:
代码实现方式如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
a = {'xs':123456,'weibinf':654321,'fanweibin':123321}
exitt = False
for i in range(3):
if not exitt:
l = open('C:\Users\Administrator\Desktop\lock.txt','r')
lock = l.readlines()
name = raw_input('Please your username: ').strip()
if len(name) != 0:
for x in lock:
x = x.strip()
if name == x :
print "\033[31mUser %s is lock\033[0m" %name
break
else:
if name in a:
xss = 0
while True:
password = raw_input("Please enter a password: ").strip()
if password.isdigit():
password = int(password)
passwd = a.get(name)
if passwd == password :
print "\033[32mWelcome System Landing success BOSS user %s \033[0m"%name
exitt = True
break
else:
xss += 1
print "\033[31mPlease password error..\033[0m"
else:
xss += 1
print "\033[31mPlease password error..\033[0m"
if xss == 3:
print "\033[31m%s is lock" %name
a = open('C:\Users\Administrator\Desktop\lock.txt','a+')
a.write('%s\n'%name)
l.close()
a.close()
break
else:
exitt = True
else:
print "\033[31mPlease your %s is null\033[0m" %name
else:
print "\033[31mPlease Input ERROR\033[0m"