账号密码输错三次即锁定

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/sen1013293436/article/details/64545220

初学Python—1

#实现账号输错三次即锁定
user = "hubery"
passwd = "123"
confirm = 0
lock=0
fileOpen = open("username.txt","a+")
fileOpen.seek(0)
for i in range(3):
    username = input("username:")
    passsword = input("password:")

    for line in fileOpen.readlines():
        if username == line.strip():
            print("账户已经锁定!")
            lock=1

            break
        else:
            continue
    fileOpen.seek(0)
    if user == username and lock ==0:
        if passwd == passsword:
            print("欢迎,欢迎!")
            confirm = 1
            break

        else:
            print("账号户或者密码错误!")
            continue
    elif lock==1:
        continue
    else:
        print("1账号或者密码错误!")
        continue
fileOpen.close()
if confirm == 0 and lock==0:
    fileWrite=open("username.txt","a")
    fileWrite.write(username+"\n")
    fileWrite.close()

基本功能可以实现;
锁定的账号为第三次输错的用户名(待完善)
以下为完善版本,如有错误,请告知

import  os
user = "hubery"
passwd = "123"
count = 0
lock = 0
fileOpen = open("username.txt", "a+")
fileOpen.seek(0)
while 1:
    for i in range(5):
        username = input("username:")
        passsword = input("password:")
        for line in fileOpen.readlines():
            if username == line.strip():
                print("账户已经锁定!")
                lock = 1
                break
            else:
                continue
        fileOpen.seek(0)
        if user == username:
            if lock == 1:
                continue
            elif passsword == passwd:
                print("欢迎,欢迎!")
                os._exit(0)
            elif count < 2:
                print("账号或者密码错误!")
                count += 1
                continue
            else:
                fileOpen.write(username + "\n")
                fileOpen.flush()
                print("密码输入错误超过三次,账户已经锁定!")
                fileOpen.seek(0)
                continue
        else:
            print("账号密码错误!")
            continue
    check=input("还想验证其他账户?(yes-继续,no-退出)")
    if "no"==check.lower():
        os._exit(0)
    else:
        continue
fileOpen.close()
展开阅读全文

没有更多推荐了,返回首页