{"record":{"id":"1f1309830ba779f1","repo":"testcontainers/testcontainers-java","slug":"password-should-be-at-least-8-characters-long","errorCode":null,"errorMessage":"Password should be at least 8 characters long","messagePattern":"Password should be at least 8 characters long","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/mssqlserver/src/main/java/org/testcontainers/containers/MSSQLServerContainer.java","lineNumber":146,"sourceCode":"    @Override\n    public String getTestQueryString() {\n        return \"SELECT 1\";\n    }\n\n    @Override\n    public SELF withPassword(final String password) {\n        checkPasswordStrength(password);\n        this.password = password;\n        return self();\n    }\n\n    private void checkPasswordStrength(String password) {\n        if (password == null) {\n            throw new IllegalArgumentException(\"Null password is not allowed\");\n        }\n\n        if (password.length() < 8) {\n            throw new IllegalArgumentException(\"Password should be at least 8 characters long\");\n        }\n\n        if (password.length() > 128) {\n            throw new IllegalArgumentException(\"Password can be up to 128 characters long\");\n        }\n\n        long satisfiedCategories = Stream\n            .of(PASSWORD_CATEGORY_VALIDATION_PATTERNS)\n            .filter(p -> p.matcher(password).find())\n            .count();\n\n        if (satisfiedCategories < 3) {\n            throw new IllegalArgumentException(\n                \"Password must contain characters from three of the following four categories:\\n\" +\n                \" - Latin uppercase letters (A through Z)\\n\" +\n                \" - Latin lowercase letters (a through z)\\n\" +\n                \" - Base 10 digits (0 through 9)\\n\" +\n                \" - Non-alphanumeric characters such as: exclamation point (!), dollar sign ($), number sign (#), \" +","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/mssqlserver/src/main/java/org/testcontainers/containers/MSSQLServerContainer.java#L128-L164","documentation":"checkPasswordStrength() enforces a minimum password length of 8 characters, matching SQL Server's policy. Shorter passwords would be rejected by the SQL Server container at startup, so testcontainers throws IllegalArgumentException early. It is raised from withPassword().","triggerScenarios":"Calling withPassword() with a String shorter than 8 characters, e.g. withPassword(\"pass123\") (7 chars).","commonSituations":"Using weak test passwords like \"admin\" or \"sa123\" in test configs; shortened passwords generated by tooling; copying examples without strengthening the sample password.","solutions":["Use a password of at least 8 characters that also meets the 3-of-4 category rule","Generate a strong test password, e.g. \"yourStrong(!)Password\"","Check length before calling withPassword()"],"exampleFix":"// before\ncontainer.withPassword(\"pass123\");\n// after\ncontainer.withPassword(\"pass1234!\");","handlingStrategy":"validation","validationCode":"if (password == null || password.length() < 8) { throw new IllegalArgumentException(\"Password must be at least 8 characters\"); }","typeGuard":null,"tryCatchPattern":"try { container.withPassword(pw); } catch (IllegalArgumentException e) { throw new IllegalStateException(\"Weak SA password: \" + e.getMessage(), e); }","preventionTips":["Use a shared constant strong test password across the test suite","Add a length assert in test setup before container construction"],"tags":["testcontainers","mssql","password","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"8e549514e3f01c57d70546fbb8599d138f3903e5","analyzedAt":"2026-09-12T14:56:41.227Z","contentChangedAt":"2026-09-12T14:56:41.227Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}