制作一个银行卡登录系统


import os

import time

import json

count = 0

exit_flag = False  #设定退出的标志

while count < 3:

    user = input('请输入用户名:')

    f = user.strip()+".json"  #用strip()去除空格

    if os.path.exists(f):

        fp = open(f,"r+",encoding='utf-8')

        j_user = json.load(fp)

        if j_user["status"] == 1:

            print('账号已经锁定')

            break

        else:

            expire_dt = j_user["expire_date"]

            current_st = time.time()

            expire_st = time.mktime(time.strptime(expire_dt,"%Y-%m-%d"))

           

            if current_st > expire_st:

                print("此用户已经过期")

                break

            else:

                while count < 3:

                    pwd = input("请输入密码:")

                    if pwd.strip() == j_user["password"]:

                        print("恭喜你,登录成功!")

                        exit_flag = True

                        break

                    else:

                        if count == 2:

                            print("密码错误超过3次,账号已锁定")

                            j_user["status"] = 1

                            fp.seek(0) # 表示从0个字节开始

                            fp.truncate() #清空文件内容

                            json.dump(j_user,fp)

                    count +=1

    if exit_flag:

        break

    else:

        print("用户不存在")

        count +=1

posted on 2019-01-18 15:17  Billchen1991  阅读(105)  评论(0)    收藏  举报

导航