1. 程式人生 > >用python寫登陸介面

用python寫登陸介面

端午佳節,一邊吃粽子一邊寫登陸介面

#!/usr/bin/env python
def login(username, password):
    f = open("db", 'r')  # 讀檔案
    for line in f:
        l1 = line.split("|")
        if l1[0] == username and l1[1] == password:
            return True
    return False


def regedit(username, password):
    f = open("db", 'a')  # a表示新增
temp = "\n" + username + "|" + password f.write(temp) f.close() def main(): a = input("1:登陸,2:註冊") if a == "1": username = input("請輸入使用者名稱:") password = input("請輸入密碼:") r = login(username, password) if r == True: print("登陸成功") else
: print("登陸失敗") elif a == "2": print("註冊") user = input("請輸入使用者名稱:") passwd = input("請輸入密碼:") regedit(user, passwd) main()