day11作业

登录系统 (函数封装)

import File_operation


def register():
    while True:
        reg_id = input('请输入注册名字(3-6位):')
        if 3 < len(reg_id) < 6:
            break
        else:
            print('注册有误,请重试')
    while True:
        reg_pa = input('请输入密码(6-12位):')
        if 6 < len(reg_pa) < 12:
            break
        else:
            print('密码输入有误,请重试')

    res = File_operation.file_json_r('file/stu_info.json')
    if not res:
        res = {}
    elif reg_id in res:
        print('这个ID 已经被注册')
        return
    else:
        res[reg_id] = reg_pa
        File_operation.file_json_w('file/stu_info.json', res)
        print('注册成功')


def login():
    name = input('请输入你的名字:')
    pass_word = input('请输入你的密码:')
    re = File_operation.file_json_r('stu_info.json')
    if name in re:
        if re[name] == pass_word:
            print('登录成功')
        else:
            print('密码错误')
    elif not re:
        print('登录失败,账号没有注册')
    else:
        print('登录失败')


def show_main_page():
    while True:
        re = File_operation.file_open('file/login_interface')
        print(re)
        choose = input('Please select number:')
        if choose == '1':
            login()
        elif choose == '2':
            register()
        else:
            break

if __name__ == '__main__':
    show_main_page()

你可能感兴趣的:(day11作业)