• 用户登陆检验----没有优化,大神可以帮忙优化优化


    import json
    ###检查输入的用户是否被锁
    def UserLogin():
        UserFile = open("UserFile.text", "rb")
        UserInput = input("请输入账号:")
        UserRead = json.load(UserFile)
        for UserRead_ in UserRead:
            if UserRead_["UserID"] == UserInput:
                print("[%s]该用户亦被锁,请联系管理员!"%UserInput)
                exit()
            else:
                UserPass(UserInput)
        UserFile.close()
    lock_List = []
    ###用户锁定读取文件
    def Userlock(lock,UserInput):
        for lock_list in lock:
            lock_List.append(lock_list)
        UserLock(lock_List,UserInput)
    ###用户锁定修改
    def UserLock(lock_List,UserInput):
        lock_List.append({"UserID":UserInput})
        UserLock__ = open("UserFile.text","w")
        UserLock_ = json.dump(lock_List,UserLock__)
        print("您的[%s]账户被冻结,请联系管理员!!!"% UserInput)
        UserLock__.close()
    ###检查用户输入的账号是否存在,如果存在就输入密码,如果不存在就提示用户
    def UserPass(UserInput):
        UserPassRead = open("UserReadFile.text","rb")
        User_PassRead = json.load(UserPassRead)
        count_1 = 0
        for Userread_ in User_PassRead:
            count_1 += 1
            if Userread_["UserID"] == UserInput :
                count_ = 0
                while count_ < 3:
                    count_ += 1
                    User_Pass = input("请输入密码:")
                    if Userread_["UserPass"] == User_Pass:
                        print("[%s]欢迎您"%UserInput)
                        exit()
                    elif count_ < 3:
                        print("密码错误,请重新输入!!您还剩[%s]" % (3 - count_))
                    elif count_ == 3:
                        k = open("UserFile.text","rb")
                        lock=json.load(k)
                        Userlock(lock,UserInput)
                        k.close()
                        exit()
            elif len(Userread_) == count_1:
                print("[%s]该账号还未注册"%UserInput)
                print("您可以前往注册(a)/重新输入账号(b)")
                Input_ = input("a/b:")
                if Input_ == "a":
                    exit()
                else:
                    UserLogin()
        UserPassRead.close()
    UserLogin()
    [{"UserID": "123"}, {"UserID": "122"}, {"UserID": "121"}, {"UserID": "120"}, {"UserID": "124"}, {"UserID": "1341"}]
    [{"UserID": "1341", "UserPass": "13421731041"},{"UserID": "13421731047", "UserPass": "13421731041"}]
    以上内容作为课堂笔记,如有雷同,请联系于我
  • 相关阅读:
    让AutoMapper更好用
    设置ADB网络连接目标板
    windos或linux中 which命令 查看当前要执行的命令所在的路径
    secureCRT使用退格键(backspace)出现^H解决办法
    Ubuntu12.04安装insight-6.8
    Linux命令之type
    BUG:给Nexus7编译Android4.2的时候出现 fatal error: map: No such file or directory
    Kconfig和Makefile的修改
    diff命令的参数详解和实例
    Linux获取当前目录名,shell获取当前目录名
  • 原文地址:https://www.cnblogs.com/ArtisticMonk/p/8967627.html
Copyright © 2020-2023  润新知