diff --git a/ocflib/account/utils.py b/ocflib/account/utils.py index ca120211..e7d8d6e8 100644 --- a/ocflib/account/utils.py +++ b/ocflib/account/utils.py @@ -40,7 +40,7 @@ def extract_username_from_principal(principal): 'ckuehl' """ - REGEX = '^([a-z]{3,16})(/[a-z]*)?@OCF\\.BERKELEY\\.EDU$' + REGEX = '^([a-z][a-z0-9]{2,15})(/[a-z]*)?@OCF\\.BERKELEY\\.EDU$' match = re.match(REGEX, principal) if not match: diff --git a/ocflib/account/validators.py b/ocflib/account/validators.py index 3b776c92..0e14ea20 100644 --- a/ocflib/account/validators.py +++ b/ocflib/account/validators.py @@ -344,8 +344,11 @@ def validate_username(username, check_exists=False): if not 3 <= len(username) <= 16: raise ValueError('Username must be between 3 and 16 characters.') - if not all(c.islower() for c in username): - raise ValueError('Username must be all lowercase letters.') + if not username[0].islower(): + raise ValueError('Username must begin with a lowercase character') + + if not all(c.islower() or c.isdigit() for c in username): + raise ValueError('Username must be only lowercase and numeric characters.') if check_exists and not user_exists(username): raise ValueError('Username does not exist.') diff --git a/tests/account/validators_test.py b/tests/account/validators_test.py index 216745cb..ac1a4e86 100644 --- a/tests/account/validators_test.py +++ b/tests/account/validators_test.py @@ -26,7 +26,6 @@ class TestValidateUsername: 'Ckuehl', 'ckuehl!', '123123', - 'f00f00', ]) def test_failure(self, username): with pytest.raises(ValueError):