29 lines
869 B
Python
29 lines
869 B
Python
import re
|
|
|
|
INVALID_PASSWORD_MESSAGE = 'Invalid password, password must be at least ' + \
|
|
'8 characters and contain no whitespace.'
|
|
|
|
def validate_email(email_address):
|
|
if re.match(r'[^@]+@[^@]+\.[^@]+', email_address):
|
|
return True
|
|
return False
|
|
|
|
|
|
def validate_username(username):
|
|
# Based off the restrictions defined in the Docker Registry API spec
|
|
regex_match = (re.search(r'[^a-z0-9_]', username) is None)
|
|
if not regex_match:
|
|
return (False, 'Username must match expression [a-z0-9_]+')
|
|
|
|
length_match = (len(username) >= 4 and len(username) <= 30)
|
|
if not length_match:
|
|
return (False, 'Username must be between 4 and 30 characters in length')
|
|
|
|
return (True, '')
|
|
|
|
|
|
def validate_password(password):
|
|
# No whitespace and minimum length of 8
|
|
if re.search(r'\s', password):
|
|
return False
|
|
return len(password) > 7
|