博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python练习-登陆三次锁定
阅读量:7053 次
发布时间:2019-06-28

本文共 753 字,大约阅读时间需要 2 分钟。

 

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

# -*- coding:utf-8 -*-#登录三次失败锁定用户count = 0true_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()

  

转载于:https://www.cnblogs.com/adamans/articles/7495380.html

你可能感兴趣的文章