以下是一个简单的 Python 示例,通过文件存储账号信息并实现多账号登录的功能: ```python import hashlib # 读取账号信息文件 def read_accounts(): accounts = {} with open('accounts.txt', 'r') as file: for line in file.readlines(): username, password = line.strip().split(',') accounts[username] = password return accounts # 登录验证 def login(): accounts = read_accounts() username = input("请输入用户名: ") password = input("请输入密码: ") hashed_password = hashlib.md5(password.encode()).hexdigest() if username in accounts and accounts[username] == hashed_password: print("登录成功") else: print("登录失败") if __name__ == "__main__": login() ``` 在上述代码中,我们假设账号信息存储在一个名为 `accounts.txt` 的文件中,每行格式为 `用户名,密码`,密码使用 `MD5` 进行简单的哈希处理。 请根据实际需求修改文件路径、存储格式和验证逻辑。 [2024-11-09 03:21:20 | AI写代码神器 | 261点数解答]