python练习-登陆三次锁定

 

读取黑名单,三次计数,写入黑名单

# -*- coding:utf-8 -*-

#登录三次失败锁定用户


count = 0
true_username = "adamander"
true_password = "123456"

#读取黑名单的内容
f = open('black_user',mode='r',encoding="utf8")
lock_file = f.read()
f.close()

username = input("用户名:")

#判断输入的用户名是否在黑名单内,如果在则不允许继续输入密码
for i in range(1):
    if lock_file == username:
        print("用户名已锁定,请联系管理员!")
        exit()
    else:
        continue

#尝试输入密码,并将输入次数进行计数
for i in range(3):
    password = input("密 码:")
    if password == true_password:
        print("登录成功!")
        break
    else:
        print("登录失败!")
    count += 1

#如果错误密码输入了三次,则提示用户名锁定,并将用户名放入黑名单中
if count == 3:
    print("您输入的密码错误次数已3次,账户已锁定!")
    f = open('black_user','w')
    f.write('%s'%username)
    f.close()

  

posted @ 2017-09-08 16:45  Adamanter  阅读(130)  评论(0编辑  收藏  举报