A Java-based password validation system with comprehensive rule checking and exception handling.
- Java 8 or higher
- No external dependencies
Create the bin directory for compiled classes:
mkdir binCompile all source files in order:
javac -d bin exception/*.java model/*.java rule/*.java service/*.java Main.javaCompile test files:
javac -d bin PasswordValidatorTest.javaRun the main application:
java -cp bin MainRun the unit tests:
java -cp bin PasswordValidatorTestThe system implements 5 validation rules:
- Not Null (Mandatory) - Password cannot be null
- Minimum Length - Password must be longer than 8 characters
- Uppercase Letter - Must contain at least one uppercase letter (A-Z)
- Lowercase Letter - Must contain at least one lowercase letter (a-z)
- Number - Must contain at least one digit (0-9)
Strict Mode - All 5 rules must pass. Returns a ValidationResult object with detailed error messages if validation fails.
Easy Mode - At least 3 of 5 rules must pass, but the not-null and lowercase rule is mandatory. Returns a boolean value indicating if the password is acceptable.
The PasswordValidator interface provides two methods:
validate(String password) - Performs strict validation and returns a ValidationResult containing validation status and any error messages.
isPasswordOk(String password) - Performs easy validation and returns true if the password meets minimum requirements (not null, lowercase and at least 1 of 3 other rules pass).
Create an instance of PasswordValidatorImpl and call the appropriate validation method. For strict validation, check if the result is valid and handle errors accordingly. For relaxed validation, simply check the boolean return value.
- Clean code architecture with separation of concerns
- Custom exception hierarchy for detailed error messages
- Strategy pattern for flexible rule implementation
- Parallel processing for performance optimization
- Comprehensive JavaDoc documentation
- Unit tests included