EasyPython

Parse Basic Auth Header

PythonHTTPSecurity

Parse an HTTP Authorization: Basic <base64> header into credentials.

solve('Basic dXNlcjpwYXNz'){'username': 'user', 'password': 'pass'}

Use Python's built-in `base64` module.

Rules:

  • Return None for a missing/invalid prefix, missing colon, or invalid base64.
  • The first : separates username from password; the password may contain colons.

Sample tests

Test #1Standard credentials
Input: ["Basic dXNlcjpwYXNz"]
Output: {"password":"pass","username":"user"}
Test #2Admin credentials
Input: ["Basic YWRtaW46c2VjcmV0"]
Output: {"password":"secret","username":"admin"}
Test #3Empty string returns None
Input: [""]
Output: null
Test #4Wrong scheme returns None
Input: ["Bearer eyJhbGci..."]
Output: null
Test #5Minimal credentials
Input: ["Basic YTpi"]
Output: {"password":"b","username":"a"}