February 2011
Intermediate to advanced
332 pages
9h 3m
English
So, let's write a dummy Python script that can act as a Basic authentication helper:
#!/usr/bin/env python
import sys
def validate_credentials(username, password):
"""
Returns True if the username and password are valid.
False otherwise
"""
# Write your own function definition.
# Use mysql, files, /etc/passwd or some service you want
return False
if __name__ == '__main__':
while True:
# Read a line from stdin
line = sys.stdin.readline()
# Remove '\n' from line
line = line.strip()
# Check if string contains two entities parts = line.split(' ', 1) if len(parts) == 2: # Extract username and password from line username, password = parts # Check if username and password are valid if validate_credentials(username, ...Read now
Unlock full access