```python
import hashlib
users = {}
def register(username, password):
if username in users:
print("用户名已存在")
return False
else:
users[username] = hashlib.md5(password.encode()).hexdigest()
print("注册成功")
return True
def login(username, password):
if username not in users:
print("用户名不存在")
return False
elif users[username] != hashlib.md5(password.encode()).hexdigest():
print("密码错误")
return False
else:
print("登录成功")
return True
def main():
while True:
operation = input("请输入操作(1-注册,2-登录,3-退出):")
if operation == "1":
username = input("请输入用户名:")
password = input("请输入密码:")
register(username, password)
elif operation == "2":
username = input("请输入用户名:")
password = input("请输入密码:")
login(username, password)
elif operation == "3":
break
else:
print("输入错误,请重新输入")
if __name__ == "__main__":
main()
```
import hashlib
users = {}
def register(username, password):
if username in users:
print("用户名已存在")
return False
else:
users[username] = hashlib.md5(password.encode()).hexdigest()
print("注册成功")
return True
def login(username, password):
if username not in users:
print("用户名不存在")
return False
elif users[username] != hashlib.md5(password.encode()).hexdigest():
print("密码错误")
return False
else:
print("登录成功")
return True
def main():
while True:
operation = input("请输入操作(1-注册,2-登录,3-退出):")
if operation == "1":
username = input("请输入用户名:")
password = input("请输入密码:")
register(username, password)
elif operation == "2":
username = input("请输入用户名:")
password = input("请输入密码:")
login(username, password)
elif operation == "3":
break
else:
print("输入错误,请重新输入")
if __name__ == "__main__":
main()
```