(request)
return username, password
Returns tuple of (username, password). Tuple values
    may be null.
Returns tuple of (username, password). Tuple values
    may be null.
Returns tuple of ( username password ) . Tuple values may be null .
def get_username_and_password_from_request(request):
    """Returns tuple of (username, password). Tuple values
    may be null."""
    from corehq.apps.hqwebapp.utils import decode_password

    if 'HTTP_AUTHORIZATION' not in request.META:
        return None, None

    @sensitive_variables()
    def _decode(string):
        try:
            return string.decode('utf-8')
        except UnicodeDecodeError:
            # https://sentry.io/dimagi/commcarehq/issues/391378081/
            return string.decode('latin1')

    auth = request.META['HTTP_AUTHORIZATION'].split()
    username = password = None
    if auth[0].lower() == DIGEST:
        try:
            digest = parse_digest_credentials(request.META['HTTP_AUTHORIZATION'])
            username = digest.username.lower()
        except UnicodeDecodeError:
            pass
    elif auth[0].lower() == BASIC:
        try:
            username, password = _decode(base64.b64decode(auth[1])).split(':', 1)
        except binascii.Error:
            return None, None
        username = username.lower()
        # decode password submitted from mobile app login
        password = decode_password(password)
    return username, password
def get_username_and_password_from_request ( request ) : from corehq . apps . hqwebapp . utils import decode_password if 'HTTP_AUTHORIZATION' not in request . META : return None , None @ sensitive_variables ( ) def _decode ( string ) : try : return string . decode ( 'utf-8' ) except UnicodeDecodeError : # https://sentry.io/dimagi/commcarehq/issues/391378081/ return string . decode ( 'latin1' ) auth = request . META [ 'HTTP_AUTHORIZATION' ] . split ( ) username = password = None if auth [ 0 ] . lower ( ) == DIGEST : try : digest = parse_digest_credentials ( request . META [ 'HTTP_AUTHORIZATION' ] ) username = digest . username . lower ( ) except UnicodeDecodeError : pass elif auth [ 0 ] . lower ( ) == BASIC : try : username , password = _decode ( base64 . b64decode ( auth [ 1 ] ) ) . split ( ':' , 1 ) except binascii . Error : return None , None username = username . lower ( ) # decode password submitted from mobile app login password = decode_password ( password ) return username , password