• 第四次作业


    import hmac
    print("*" * 20)
    print("1.注册")
    print("2.登录")
    print("*" * 20)
     
    def login_register():
        user = input("user:")
        psw = input("passwd:")
        return user, psw

    # 调取文件中的密码
    def land_passwd(acca):
        with open("user_passwd.txt", "rt") as passwod:
            use_passwd = passwod.read()
            a = eval(use_passwd)
            for k in a:
                if acca == k:
                    print(k, a[k])
                    return k, a[k]
      
    # 注册时,用户名和生成密文保存在passwd.txt文件
    def encrypt(user_acc, origin_password):
        md5 = hmac.new(origin_password.encode("utf-8"), "hahaha".encode("utf-8"), "md5")
        encrypt_text = md5.hexdigest()
        passwd_dict = dict()
        passwd_dict[user_acc] = encrypt_text
     
        with open("user_passwd.txt", "a") as password:
            password.write(str(passwd_dict))
            password.write("\n")
     
        password.close()
     
    # 登陆时密码加密的密文
    def land_encrypt(origin_password):
        md5 = hmac.new(origin_password.encode("utf-8"), "hahaha".encode("utf-8"), "md5")
        return md5.hexdigest() 
    num = input("请输入数字“1”或“2”:")
     
    if num == "1":
        acc, passwd = login_register()
        encrypt(acc, passwd)
    elif num == "2":
        acc, passwd = login_register()
        user_ac, user_passwd = land_passwd(acc)
        if user_ac == acc and land_encrypt(passwd) == user_passwd:
            print("登陆成功!")
        else:
            print("用户名或者密码错误")
    else:
        print("输入错误!!!请输入数字”1“或”2“")

    2.

    class Shape:
        def __init__(self, x, y):
            self.__x = x
            self.__y = y
     
            @property
            def X(self):
                return str(self.__x)
     
            @X.setter
            def Age(self):
                self.__age = x
     
            @property
            def Y(self):
                return str(self.__y)
     
            @Y.setter
            def Age(self):
                self.__age = y
     
     
    class Rectangle(Shape):
        def __init__(self, w, h, x, y):
            super().__init__(x, y)
            self.x = x
            self.y = y
            self.w = w
            self.h = h
     
        def contain(self, x, y):  # 判断坐标是否在矩形中
            if (self.x - x) ** 2 > self.w ** 2 and (self.y - y) > self.h ** 2:
                raise Exception("不在里面")
            else:
                print(f"点{x,y}在里面")
     
     
    class Cirle(Shape):
        def __init__(self, r, x, y):
            super().__init__(x, y)
            self.r = r
            self.x = x
            self.y = y
     
        def contain(self, x, y):  # 判断坐标是否在圆形中
            if (self.x - x) ** 2 + (self.y - y) ** 2 > self.r ** 2:
                raise Exception("不在里面")
            else:
                print(f"点{x,y}在里面")

  • 相关阅读:
    【微处理器】基于FPGA的微处理器VHDL开发
    hadoop生态圈之hive面试(一)
    Docker部署Emqx并配置ssl支持微信小程序
    C++函数如何具有多个返回值?
    Spring文章汇总
    2022“杭电杯”中国大学生算法设计超级联赛(8)
    jquery-picture-cut 任意文件上传 (CVE-2018-9208)
    wandb----误删除了run怎么找回
    【模型训练】YOLOv7不同颜色安全帽佩戴检测
    新闻速递 | MobTech袤博科技参与中国信通院“绿色SDK产业生态共建行动”
  • 原文地址:https://blog.csdn.net/m0_65548364/article/details/133615316