python登录注册系统
时间: 2023-08-13 13:07:26 浏览: 41
这是一个简单的 Python 登录注册系统示例:
```python
import hashlib
users = {}
def register():
username = input("请输入用户名:")
password = input("请输入密码:")
password_hash = hashlib.sha256(password.encode('utf-8')).hexdigest()
users[username] = password_hash
print("注册成功!")
def login():
username = input("请输入用户名:")
password = input("请输入密码:")
password_hash = hashlib.sha256(password.encode('utf-8')).hexdigest()
if username in users and users[username] == password_hash:
print("登录成功!")
else:
print("用户名或密码错误!")
while True:
print("请选择操作:")
print("1. 注册")
print("2. 登录")
choice = input()
if choice == "1":
register()
elif choice == "2":
login()
else:
print("无效的选择!")
```
在这个示例中,我们使用了 Python 的 hashlib 模块来计算密码的哈希值,以增加安全性。注意,这只是一个简单的示例,实际应用中需要更多的安全措施。