Password Validator - (2%)

Due date: In class 10/13/2025


1. Program Requirements

Use Scanner to take the password input from the user.

2. Password Strength Conditions

Your password must meet the following conditions:

3. Expected Outputs

Example 1: Strong Password
Enter your password: Pass@word1
Output: Password is strong.
Example 2: Weak Password (No Special Character)
Enter your password: Password1
Output: Password does not meet the required conditions.
Example 3: Weak Password (Too Short)
Enter your password: P@1
Output: Password does not meet the required conditions.

4. Java Code Section

Paste or view your Java code below:


// PasswordValidator.java
import java.util.Scanner;

public class PasswordValidator {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter your password: ");
        String password = scanner.nextLine();

        if (isValidPassword(password)) {
            System.out.println("Password is strong.");
        } else {
            System.out.println("Password does not meet the required conditions.");
        }

        scanner.close();
    }

    public static boolean isValidPassword(String password) {
        if (password.length() < 8) {
            return false; // Must be at least 8 characters
        }

        boolean hasDigit = false;
        boolean hasSpecialChar = false;
        String specialCharacters = "!@#$%^&*()_+-=[]{};:'\"\\|,.<>?/";

        for (char ch : password.toCharArray()) {
            if (Character.isDigit(ch)) {
                hasDigit = true;
            }
            if (specialCharacters.indexOf(ch) != -1) {
                hasSpecialChar = true;
            }
            if (hasDigit && hasSpecialChar) {
                return true; // If both conditions are met, no need to check further
            }
        }

        return false;
    }
}
            

5. How to Submit on Blackboard?