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

  1. Check each rule separately
  2. Collect all failures
  3. Report all issues at once

Related Exception Handling exercises

Practice all Exception Handling exercises · Run this idea in the Java compiler