import hashlib
UI = """
************
1.注册
2.登录
************
"""
salt = '1835929550zzsqq'
# print(UI)
# select = int(input('请输入正确的序号:'))
def register():
account = input('请输入账号:')
password = input('请输入密码:')
password = encrypt(password)
with open("password.txt", "a") as f:
f.writelines(account + ":" + password + "\n")
f.close()
def login():
account = input('请输入账号:')
password = input('请输入密码:')
password = encrypt(password)
dc = from_password()
if account in dc:
if dc[account] == password:
print("登录成功")
else:
print("密码错误")
else:
print("账号不存在")
def from_password():
ls = []
with open("password.txt", "r") as f:
while True:
s = f.readline().replace("\n","")
ls.append(s)
if s == "":
break
dc = dict()
for iteam in ls:
ac_pwd = iteam.split(":")
if len(ac_pwd) >= 2:
dc[ac_pwd[0]] = ac_pwd[1]
return dc
def encrypt(pwd: str):
md5 = hashlib.md5(pwd.encode())
md5.update(salt.encode())
return md5.hexdigest()
while True:
print(UI)
select = int(input('请输入正确的序号:'))
if select == 1:
register()
elif select == 2:
login()
import math
class Shape:
def __init__(self, center_x, center_y):
self._center_x = center_x
self._center_y = center_y
class Rectangle(Shape):
def __init__(self, center_x, center_y, w, h):
super().__init__(center_x, center_y)
self.width = w
self.height = h
def is_in(self, x, y):
if self._center_x + self.width / 2 > x > self._center_x - self.width / 2 \
and self._center_y + self.height / 2 > y > self._center_y - self.height / 2:
return True
else:
return False
class Circle(Shape):
def __init__(self, center_x, center_y, r):
super().__init__(center_x, center_y)
self.r = r
def is_in(self, x, y):
if math.sqrt((x - self._center_x) ** 2 + (y - self._center_y) ** 2) <= self.r:
return True
else:
return False