Challenge - 5 Problems
Basic Authentication Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Basic Authentication header decoding?
Given the HTTP header
Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l, what is the decoded username and password?Rest API
import base64 header = 'Basic QWxhZGRpbjpPcGVuU2VzYW1l' encoded = header.split()[1] decoded = base64.b64decode(encoded).decode('utf-8') print(decoded)
Attempts:
2 left
💡 Hint
Remember Basic Authentication encodes username and password as base64 of 'username:password'.
✗ Incorrect
The string after 'Basic' is base64 encoded. Decoding it reveals the username and password separated by a colon.
🧠 Conceptual
intermediate1:30remaining
What error occurs if the Basic Authentication header is missing?
If a REST API endpoint requires Basic Authentication but the client sends no Authorization header, what HTTP status code should the server respond with?
Attempts:
2 left
💡 Hint
Think about what status code means 'authentication required'.
✗ Incorrect
401 Unauthorized means the client must authenticate to get the requested response.
🔧 Debug
advanced2:30remaining
Why does this Basic Authentication code fail to authenticate?
This Python code snippet is intended to check Basic Authentication but always fails. Why?
auth_header = request.headers.get('Authorization')
if auth_header:
encoded = auth_header.split(' ')[1]
decoded = base64.b64decode(encoded).decode('utf-8')
username, password = decoded.split(':')
if username == 'admin' and password == '1234':
return 'Access granted'
return 'Access denied'Rest API
auth_header = request.headers.get('Authorization') if auth_header: encoded = auth_header.split(' ')[1] decoded = base64.b64decode(encoded).decode('utf-8') username, password = decoded.split(':') if username == 'admin' and password == '1234': return 'Access granted' return 'Access denied'
Attempts:
2 left
💡 Hint
Consider what happens if the header is missing or malformed.
✗ Incorrect
If the Authorization header is missing or does not contain a space, split(' ')[1] will cause an IndexError. The code lacks error handling for these cases.
📝 Syntax
advanced2:00remaining
Which option correctly forms a Basic Authentication header in Python?
You want to create a Basic Authentication header for username 'user' and password 'pass'. Which code snippet correctly creates the header string?
Attempts:
2 left
💡 Hint
Remember to encode string to bytes before base64 encoding, then decode back to string.
✗ Incorrect
Option B correctly encodes the credentials string to bytes, base64 encodes it, then decodes back to string to form the header.
🚀 Application
expert3:00remaining
How many valid username-password pairs can be extracted from this Basic Authentication header?
Given the HTTP header
Authorization: Basic dXNlcjE6cGFzczEsdXNlcjI6cGFzczI=, how many valid username-password pairs does it contain when decoded?Attempts:
2 left
💡 Hint
Basic Authentication encodes a single 'username:password' pair, not multiple pairs separated by commas.
✗ Incorrect
The base64 string decodes to 'user1:pass1,user2:pass2' which is a single string, not two separate pairs. Basic Auth expects one pair only.