发布于2019-08-06 10:51 阅读(642) 评论(0) 点赞(2) 收藏(5)
1.登陆账号
user_dic ={'username':None,'login':False} def auth_func(func): def wrapper(*args,**kwargs): if user_dic['username'] and user_dic['login']: res = func(*args,**kwargs) return res username = input('账号:').strip() passwd = input('密码:').strip() if username == 'abcd' and passwd == '123456': user_dic['username'] = username user_dic['login'] = True print('登陆成功!') res=func(*args,**kwargs) return res else: print('用户名或密码错误') return wrapper @auth_func def index(): print('欢迎光临本网站') @auth_func def home(name): print('欢迎%s回家' % name) index() home('小明')
运行结果:
账号:abcd 密码:123456 登陆成功! 欢迎小明回家 Process finished with exit code 0
2.检测已有账号登陆
user_list=[{'name':'abcd','passwd':'123456'}, {'name':'abd','passwd':'123'}, {'name':'acc','passwd':'123456'}, {'name':'asdfg','passwd':'12346'} ] user_dac ={'username':None,'login':False} # 获取刚开始登陆之前的状态 def auth_func(func): def wrapper(*args,**kwargs): if user_dac['username'] and user_dac['login']: # 获取刚开始登陆之前的状态,是否已登录 res = func(*args,**kwargs) return res username = input('账号:').strip() passwd = input('密码:').strip() for user_dic in user_list: if username == user_dic['name'] and passwd == user_dic['passwd']: user_dac['username'] = username user_dac['login'] = True print('登陆成功!') res=func(*args,**kwargs) return res else: print('用户名或密码错误') return wrapper @auth_func def index(): print('欢迎光临本网站') @auth_func def home(name): print('欢迎%s回家' % name) index() home('sb')
运行结果:
账号:abd 密码:123 登陆成功! 欢迎光临本网站 欢迎sb回家 Process finished with exit code 0
作者:我不喜欢上班
链接:https://www.pythonheidong.com/blog/article/7921/35572504c710a088ab8d/
来源:python黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 python黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-1
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!