day13 - 寫一個登陸註冊的頁面

weixin_41810571發表於2020-10-16

# 寫一個登陸註冊的頁面,要求已經註冊過的賬號不能再註冊:已經註冊的賬號才能登陸,並且登陸的密碼必須和註冊的密碼一致

def reg_log():
    str1 = """
=====================================
        ** 歡迎來到xx網使用者管理系統 **

            ♦ 1. 登        錄
            ♦ 2. 注        冊
            ♦ 3. 退        出   

=====================================            
    """
    print(str1)
    f = open('information.txt', 'a')
    f = open('information.txt')
    s = f.read()
    if len(s) == 0:
        f = open('information.txt', 'a')
        f.write('{}')
        f.close()
    accounts = {}
    number = int(input('請選擇(1-3):'))
    account = input('請重新輸入賬號(3~6位):')
    password = input('請輸入密碼(6~12位):')
    if not(3 <= len(account) <= 6 and 6 <= len(password) <= 12):
        print('賬號或者密碼錯誤格式錯誤')
        reg_log()
    accounts[account] = password
    f = open('information.txt')
    userinfo = eval(f.read())
    f.close()
    if number == 3:
        return 0
    elif number == 1:
        if account in userinfo:
            print('登入成功')
        elif account not in userinfo:
            print('賬號不存在,請註冊!')
            reg_log()
        else:
            print('登入失敗,密碼錯誤')
            reg_log()
    elif number == 2:
        if account in userinfo and userinfo[account] == password:
            print('註冊失敗!該賬號已被註冊!')
            reg_log()
        else:
            userinfo.update(accounts)
            f = open('information.txt', 'w')
            f.write(str(userinfo))
            f.close()
            print('註冊成功,請登入!')
            reg_log()
    return 0


 reg_log()






相關文章