登录认证

用户跳转一个界面就要输入一次密码,所以通过设置一个状态值,来保存以登录的状态

 1 def auth():
 2     username = input("username:").strip()
 3     password = input("password:").strip()
 4     #get data from db
 5     _username = "a"
 6     _password = "a"
 7     if username == _username and password == _password:
 8         print("passed authentication!")
 9         global login_status
10         login_status = True #局部变量
11         print("-->",login_status)
12         return True, 1,2
13         print("after return ....")
14     else:
15         return False
16 
17 def home():
18     if login_status == True:
19         print("welcome to home page")
20     else:
21         auth()
22 def pay():
23     if login_status == True:
24         print("welcome to pay page")
25     else:
26         auth()
27 
28 login_status = auth()
29 print(login_status)
30 
31 # print(login_status)
32 auth()
33 home()
34 pay()

 

posted @ 2016-12-03 16:18  wangmo  阅读(500)  评论(0编辑  收藏  举报