python 登入接口

'''
编写登陆接口

•输入用户名密码
•认证成功后显示欢迎信息
•输错三次后锁定
•并且用户名被就在restrictuser.txt下面,如果想解除锁定就要到文本下面删除user
'''

countnumber=0
while countnumber <3: ###输入三次错误后锁定
#    for i in  open (r"D:\Python\userpasswd.txt").readlines():
    username = input("Please input the username:")
    password = input("Please input the passwd:")
    f1 = open(r'D:\Python\restrictuser.txt').read()
    rest=f1.count(username)
    print(rest)
    if rest >= 3:
        print("Your ID have been locked,Please contact the administrator")
        exit()
    i = open(r"D:\Python\userpasswd.txt").read()
#    print(i.split(" ")[1].strip())
#    print(type(i.split(" ")[0]))
#    break
    if username == i.split(" ")[0].strip()  and password == i.split(" ")[1].strip():
        print ("Welcome Login")
        exit()
    else:
        print("You have %s chance"%(2-countnumber))
        countnumber+=1
        f = open(r'D:\Python\restrictuser.txt','a')
        f.writelines('\n' + username )
        f.close()
        continue
else:
    print("Your ID have been locked")
    exit()
#a = f.readline()
#print (f)
#错误信息
#SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 9-10: truncated \uXXXX escape

#print (username,password)

 

posted @ 2017-06-27 11:11  陈奕迅-可以了  阅读(164)  评论(0编辑  收藏  举报