(request, response, realm, users, encrypt=None)
return False
Check Authentication

    If an Authorization header contains credentials, return True, else False.

    :param realm: The authentication realm.
    :type  realm: str

    :param users: A dict of the form: {username: password} or a callable
                  returning a dict.
    :type  users: dict or callable

    :param encrypt: Callable used to encrypt the password returned from
                    the user-agent. if None it defaults to a md5 encryption.
    :type  encrypt: callable
Check Authentication
Check Authentication
def check_auth(request, response, realm, users, encrypt=None):
    """Check Authentication

    If an Authorization header contains credentials, return True, else False.

    :param realm: The authentication realm.
    :type  realm: str

    :param users: A dict of the form: {username: password} or a callable
                  returning a dict.
    :type  users: dict or callable

    :param encrypt: Callable used to encrypt the password returned from
                    the user-agent. if None it defaults to a md5 encryption.
    :type  encrypt: callable
    """

    if "Authorization" in request.headers:
        # make sure the provided credentials are correctly set
        ah = _httpauth.parseAuthorization(request.headers.get("Authorization"))
        if ah is None:
            return httperror(request, response, 400)

        if not encrypt:
            encrypt = _httpauth.DIGEST_AUTH_ENCODERS[_httpauth.MD5]

        if isinstance(users, collections.Callable):
            try:
                # backward compatibility
                users = users()  # expect it to return a dictionary

                if not isinstance(users, dict):
                    raise ValueError("Authentication users must be a dict")

                # fetch the user password
                password = users.get(ah["username"], None)
            except TypeError:
                # returns a password (encrypted or clear text)
                password = users(ah["username"])
        else:
            if not isinstance(users, dict):
                raise ValueError("Authentication users must be a dict")

            # fetch the user password
            password = users.get(ah["username"], None)

        # validate the Authorization by re-computing it here
        # and compare it with what the user-agent provided
        if _httpauth.checkResponse(ah, password, method=request.method,
                                   encrypt=encrypt, realm=realm):
            request.login = ah["username"]
            return True

        request.login = False
    return False
def check_auth ( request , response , realm , users , encrypt = None ) : if "Authorization" in request . headers : # make sure the provided credentials are correctly set ah = _httpauth . parseAuthorization ( request . headers . get ( "Authorization" ) ) if ah is None : return httperror ( request , response , 400 ) if not encrypt : encrypt = _httpauth . DIGEST_AUTH_ENCODERS [ _httpauth . MD5 ] if isinstance ( users , collections . Callable ) : try : # backward compatibility users = users ( ) # expect it to return a dictionary if not isinstance ( users , dict ) : raise ValueError ( "Authentication users must be a dict" ) # fetch the user password password = users . get ( ah [ "username" ] , None ) except TypeError : # returns a password (encrypted or clear text) password = users ( ah [ "username" ] ) else : if not isinstance ( users , dict ) : raise ValueError ( "Authentication users must be a dict" ) # fetch the user password password = users . get ( ah [ "username" ] , None ) # validate the Authorization by re-computing it here # and compare it with what the user-agent provided if _httpauth . checkResponse ( ah , password , method = request . method , encrypt = encrypt , realm = realm ) : request . login = ah [ "username" ] return True request . login = False return False