users_dict = {
'root':'123',
'malin':'456',
'马林':'111'}
current_ditc = {'name':None,'login':None}
def auth(auth_type='filedb'):
def auth_func(func):
def wrapper(*args,**kwargs):
print('认证类型是:%s' % auth_type)
if auth_type == 'filedb':
while True:
if current_ditc['name'] and current_ditc['login']:
res = func(*args,**kwargs)
return res
while True:
user_name = input('请输入用户名:').strip()
if user_name in users_dict.keys():
for i in [2,1,0]:
passwd = input('请输入密码:').strip()
if users_dict[user_name] == passwd:
current_ditc['name'] = True
current_ditc['login'] = True
break
if i == 0:
print('3次输入错误,请15分钟后再试')
break
print('密码错误,您还有%d次机会' % i )
break
else:
print('不存在该用户')
elif auth_type == 'ldap':
print('鬼才直到怎么玩ldap')
else:
print('没见过这种认证方式')
return wrapper
return auth_func
@auth()
def index():
print('欢迎来到主页')
return None
@auth('ldap')
def home(name):
print('欢迎%s回家'% name)
return None
@auth('filedb')
def shoping_car(*args,**kwargs):
print('购物车里都有{}{}'.format(*args,**kwargs))
return None
模拟session 用户认证
最新推荐文章于 2023-05-06 21:20:55 发布