Python實現驗證使用者資訊後跳轉網頁的功能
阿新 • • 發佈:2018-12-26
username = 'root' password = '123456' #用於驗證使用者資訊的裝飾器 def auth(type): def deco(func): def wrapper(*args,**kwargs): name = input("請輸入使用者名稱:").strip() pwd = input("請輸入密碼:").strip() if name == username and pwd == password: print("\033[32;1m登入成功!\033[0m") return func(*args,**kwargs) else: print("\033[35;1m使用者名稱或者密碼錯誤!\033[0m") return wrapper; return deco #登入介面 @auth(type="local") def login(): print("Welcome to Login") return "sucess" #主介面 @auth(type="ldap") def home(): print("Welcome to home") #評論介面 @auth(type="tourist") def comment(): print("Welcome to comment") login()