gpt4 book ai didi

python - Bottle 中的基本身份验证

转载 作者:行者123 更新时间:2023-12-04 00:30:14 27 4
gpt4 key购买 nike

如何在 Bottle 框架中执行基本身份验证?在 flask 中我曾经:

def check( username, password ):
# This function is called to check if a username/password combination is valid
return username == 'nikos' and password == '******'


def authenticate():
# Sends a 401 response that enables basic auth
return Response( 'Credentials of a registered user required!', 401, {'WWW-Authenticate': 'Basic realm="User!"'} )

并称为:
auth = request.authorization
if not auth or not counters.check( auth.username, auth.password ):
return counters.authenticate()

我如何在 Bottle 框架中实现相同的目标?

最佳答案

据报道 here , 瓶子 natively contains使 Basic Auth 非常简单的装饰器:

from bottle import auth_basic, request, route

def is_authenticated_user(user, password):
# You write this function. It must return
# True if user/password is authenticated, or False to deny access.

@route('/')
@auth_basic(is_authenticated_user)
def home():
return ['hooray, you are authenticated! your info is: {}'.format(request.auth)]

关于python - Bottle 中的基本身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52461587/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com