登录系统

"""------ __author__ ==  李  墨  ------"""
#注册,登录
'''
1.注册
    输入账号:(已经注册过的不能再注册)
    输入密码:
    提示注册成功或者失败,失败:已经注册过
    
2.登录
    输入账号:
    输入密码:
    登录成功,1)账号没有注册,2)密码错误
3.返回
'''
import json
def stu_login():
    acc_num=input('请输入账号:')
    acc_pssword=input('请输入密码:')
    return acc_num,acc_pssword
def stu_sign():
    sign_num=input('请输入账号:')
    sign_pssword=input('请输入密码:')
    return sign_num,sign_pssword


while True:
    print('='*50,'1.注册','2.登录','3.返回',sep='\n')
    choose1=int(input('请选择(1~3):'))
    with open('stu_data.txt',encoding='utf-8') as f_read:
        stu_data = f_read.read()
    if  not stu_data:
        stu_data='{"管理员":"李四"}'
    stu_dict=json.loads(stu_data,encoding='utf-8')
    if choose1==1:
        acc_num, acc_pssword=stu_login()
        if acc_num in stu_dict:
            print('账号已存在,注册失败!')
            continue
        stu_dict[acc_num]=acc_pssword
        stu_dict=json.dumps(stu_dict)
        with open('stu_data.txt', 'w',encoding='utf-8') as f_write:
            f_write.write(stu_dict)
        print('注册成功!')
    elif choose1==2:
        sign_num, sign_pssword=stu_sign()
        if sign_num not in stu_dict.keys():
            print('该账号未注册,登录失败!')
        else:
            if stu_dict[sign_num]==sign_pssword:
                print('登录成功!')
                print('❀'*50)
                break
            else:
                print('密码错误,登录失败!')
    else:
        print('see you!')
        break

你可能感兴趣的:(登录系统)