Password Validation in Java: Explanation & Practice
Validate password against multiple rules
Problem summary
Create password validator that checks length, uppercase, lowercase, and digit requirements.
Starter code
// Password must have:
// - At least 8 characters
// - At least one uppercase
// - At least one lowercase
// - At least one digit
public class Main {
public static void main(String[] args) {
String password = "weak"; // Test case 1
// Validate and report all failures
}
}Expected output and test cases
- Multiple failures
Invalid: Too short, No uppercase, No digit
- Single failure
Invalid: No uppercase
- Valid password
Password valid
Hints
- Check each rule separately
- Collect all failures
- Report all issues at once
Related Exception Handling exercises
- Practice Exception Propagation in Java
- Practice Age Range Validator in Java
- Practice Null Handling in Java
Practice all Exception Handling exercises · Run this idea in the Java compiler