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