练习1

1.编写登陆接口

2.认证成功登陆

3.连续三次错误锁定账户

 

解题思路:

1.首先需要建立一个文档用于存放正确的用户名和密码,以及程序是否有错误的用户名记录。设置一个标志变量用于判断程序是否有错误用户名记录。

2.程序执行前先读取密码文档,和标志变量。

3.程序实现。

print "Welcome to telnet here:"

count = len(open("C:文件路径","r+").readlines())     #确定密码文件行数,用于后续错误用户名的切片

f=open(r"C:文件路径","r+")                                 #打开文件

alis=[]                   #建立一个空列表用于存放文件拷贝过来的内容
fist_choice=f.readline().strip()        #拿出文件标志位
f.close()

f=open(r"C:文件路径","r+")

if fist_choice=='0':

for i in range (count):
ast=f.readline().strip()
alis.append(ast)


else:
for i in range (count):
ast=f.readline().strip()
alis.append(ast)

f.close()

usn = raw_input('请输入用户名:')
psw = raw_input('请输入密码(密码长度不低于6位):')
while 1:
if len(psw)<6 and (psw.isalpha() or psw.isdigit()) :
print "密码过于简单,请输入字母和数字的组合"
psw=raw_input('请输入密码(密码长度不低于6位):')
else:
break

n=len(alis)

if alis[0]!='0' and usn in alis[3:n]:
print "对不起该用户已经被锁定,请更换用户名!"

else:
for i in range (3):
if usn==alis[1] and psw==alis[2]:
print "欢迎来到PYTHON之家!"
break
else:
print "用户名或密码错误请重新输入"
usn = raw_input('请输入用户名:')
psw = raw_input('请输入密码(密码长度不低于6位):')
while 1:
if len(psw)<6 and (psw.isalpha() or psw.isdigit()) :
print "密码过于简单,请输入字母和数字的组合"
psw=raw_input('请输入密码(密码长度不低于6位):')
else:
break
if i==2:
f=open(r"C:文件路径","r+")
alis[0]='1'
alis.append(usn)
act="\n".join(alis)
print act
f.write(act)


f.close()

posted @ 2017-08-18 01:16  yekai5740  阅读(113)  评论(0编辑  收藏  举报