"""
===================
1.登录
2.注册
===================
请选择:1.
===================
请输入账号:
请输入密码:
登录成功!/登录失败!
===================
请选择:2.
=====================
请输入账号:
请输入密码:
注册成功!/注册失败!
"""
def save_message(user_name, password):
with open('user_message.txt', 'r', encoding='utf-8') as file:
for account_info in file.readlines():
if user_name == account_info.split(",")[0]:
print('用户名已注册')
break
else:
with open('user_message.txt', 'a', encoding='utf-8') as file:
s = f'{user_name},{password}\n'
if len(user_name) >= 6:
for x in user_name:
if not (x.islower() or x.isupper() or x.isdigit()):
print('用户名不符合规范')
break
else:
file.write(s)
print('注册成功')
else:
print('用户名不符合规范')
def read_message(user_name, password):
with open('user_message.txt', 'r', encoding='utf-8') as file:
line_info = file.readlines()
for account_info in line_info:
if user_name == account_info.split(",")[0]:
if f'{password}\n' == account_info.split(",")[1]:
print("登陆成功")
else:
print("登录失败,密码错误")
break
else:
print("登陆失败,该用户未注册")
print('=======================\n\n 1.登录\n 2.注册\n\n=======================')
user_choose = input('请选择:')
if user_choose == '1':
user_name = input('请输入用户名:')
password = input('请输入密码:')
read_message(user_name, password)
elif user_choose == '2':
user_name = input('请输入用户名:(不少于6位,且只限英文字母和数字)')
password = input('请输入密码:')
save_message(user_name, password)
else:
print('..加油,你可以的')