diff --git a/plinth/modules/backups/forms.py b/plinth/modules/backups/forms.py index 60178e54f..32f4bc23e 100644 --- a/plinth/modules/backups/forms.py +++ b/plinth/modules/backups/forms.py @@ -95,7 +95,7 @@ def repository_validator(path): hostname = hostname.split('%')[0] # Validate username using Unix username regex - if not re.match(r'[a-z_][a-z0-9_-]*$', username): + if not re.match(r'[a-z0-9_][a-z0-9_-]*$', username): raise ValidationError(_(f'Invalid username: {username}')) # The hostname should either be a valid IP address or hostname diff --git a/plinth/modules/backups/tests/test_validators.py b/plinth/modules/backups/tests/test_validators.py index 7d3a1f859..394a6d2ae 100644 --- a/plinth/modules/backups/tests/test_validators.py +++ b/plinth/modules/backups/tests/test_validators.py @@ -34,8 +34,10 @@ def test_repository_paths_validation(): def test_repository_username_validation(): """Test that usernames in repository string are validated properly.""" - valid_usernames = ['sshuser', 'cypher_punk-2077', '_user', '_-_'] - invalid_usernames = ['1two', 'somebody else'] + valid_usernames = [ + 'sshuser', 'cypher_punk-2077', '_user', '_-_', '1two', '1234' + ] + invalid_usernames = ['somebody else'] path_string = '{}@example.org:~/backups' _validate_repository(valid_usernames, invalid_usernames, path_string)