第四次作业

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}在里面")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值