Day 3 - PassGuard | #30Days30Projects

Rushikesh UngeRushikesh Unge
4 min read

Introduction

Passwords are our first line of defense on the web โ€” but how strong is your password, really? Welcome to PassGuard, a simple yet powerful Java-based CLI tool that analyzes password strength using regex-based validations.

In this post, youโ€™ll learn how to:

  • Analyze password strength using Java

  • Use regex patterns for validations

  • Add colored outputs for a better CLI experience

  • Build a fun and interactive CLI app in just under 100 lines


๐Ÿ”ง Features of PassGuard

  • Checks for length, uppercase, lowercase, digits, and special characters

  • Gives a strength score and label (Weak, Medium, Strong)

  • Provides a color-coded summary in the terminal

  • Shows a detailed breakdown of what the password contains


๐Ÿ“ Project Structure

PassGuard/
โ”‚
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ PassGuard.java
โ””โ”€โ”€ README.md

๐Ÿง  Concepts Used

  • String manipulation

  • Pattern and Matcher classes from java.util.regex

  • ANSI escape codes for colored terminal output

  • CLI input using Scanner


๐Ÿง‘โ€๐Ÿ’ป The Complete Code

package PassGuard.src;

import java.util.Scanner;
import java.util.regex.Pattern;

public class PassGuard {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        // ANSI Color Codes
        final String RESET = "\u001B[0m";
        final String RED = "\u001B[31m";
        final String YELLOW = "\u001B[33m";
        final String GREEN = "\u001B[32m";
        final String CYAN = "\u001B[36m";
        final String BOLD = "\u001B[1m";

        // Header
        System.out.println(BOLD + CYAN + "โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—");
        System.out.println("โ•‘          Welcome to PassGuard         โ•‘");
        System.out.println("โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•" + RESET);
        System.out.print("\nEnter a password to check strength: ");
        String password = sc.nextLine();

        // Score Calculation
        int strengthScore = 0;
        boolean hasLower = Pattern.compile("[a-z]").matcher(password).find();
        boolean hasUpper = Pattern.compile("[A-Z]").matcher(password).find();
        boolean hasDigit = Pattern.compile("[0-9]").matcher(password).find();
        boolean hasSpecial = Pattern.compile("[^a-zA-Z0-9]").matcher(password).find();
        boolean hasLength = password.length() >= 8;

        if (hasLength) strengthScore++;
        if (hasLower) strengthScore++;
        if (hasUpper) strengthScore++;
        if (hasDigit) strengthScore++;
        if (hasSpecial) strengthScore++;

        // Result Label
        String strengthLabel;
        String strengthColor;

        if (strengthScore <= 2) {
            strengthLabel = "Weak Password";
            strengthColor = RED;
        } else if (strengthScore <= 4) {
            strengthLabel = "Medium Password";
            strengthColor = YELLOW;
        } else {
            strengthLabel = "Strong Password";
            strengthColor = GREEN;
        }

        // Final Output
        System.out.println(BOLD + "\nโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Password Analysis โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€" + RESET);
        System.out.println(strengthColor + BOLD + ">> " + strengthLabel + RESET);

        System.out.println(BOLD + "\nโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Detailed Breakdown โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€" + RESET);
        System.out.printf("โ€ข %-13s: %s\n", "Length", hasLength ? GREEN + "Sufficient" : RED + "Too short" + RESET);
        System.out.printf("โ€ข %-13s: %s\n", "Lowercase", hasLower ? GREEN + "Present" : RED + "Missing" + RESET);
        System.out.printf("โ€ข %-13s: %s\n", "Uppercase", hasUpper ? GREEN + "Present" : RED + "Missing" + RESET);
        System.out.printf("โ€ข %-13s: %s\n", "Digits", hasDigit ? GREEN + "Present" : RED + "Missing" + RESET);
        System.out.printf("โ€ข %-13s: %s\n", "Special Char", hasSpecial ? GREEN + "Present" : RED + "Missing" + RESET);

        System.out.println(BOLD + "\nThank you for using PassGuard! Stay safe. " + RESET);
    }
}

๐Ÿ–ฅ Sample Output

Input:

Enter a password to check strength: Hello@123

Output:

โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Password Analysis โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
>> Strong Password

โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Detailed Breakdown โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
โ€ข Length        : Sufficient
โ€ข Lowercase     : Present
โ€ข Uppercase     : Present
โ€ข Digits        : Present
โ€ข Special Char  : Present

Thank you for using PassGuard! Stay safe.

๐Ÿงช How Password Strength is Calculated

Each of the following criteria gives 1 point:

  • Length โ‰ฅ 8

  • At least one lowercase letter

  • At least one uppercase letter

  • At least one digit

  • At least one special character

Total out of 5

  • 0โ€“2: Weak

  • 3โ€“4: Medium

  • 5: Strong


๐Ÿš€ How to Run It

  1. Create the folder structure:

     mkdir -p PassGuard/src
     cd PassGuard/src
     touch PassGuard.java
    
  2. Paste the code in PassGuard.java.

  3. Compile & run:

     javac PassGuard.java
     java PassGuard
    

๐Ÿ’ก What Youโ€™ll Learn

  • Regex pattern matching using Pattern.compile()

  • Colored CLI output with ANSI codes

  • Structuring and validating user input

  • Creating mini-CLI utilities with Java


โœ… What's Next?

Try extending this:

  • Add password suggestions

  • Log password strength data to a file

  • Add a GUI version using Java Swing or JavaFX


๐Ÿ“Œ Final Thoughts

Even small projects like PassGuard teach a lot about real-world Java usage. Regex, CLI design, and user experience โ€” all wrapped in one compact app.

If you're following the #30Days30Projects challenge, this is a great way to sharpen your Java fundamentals and show your work publicly.


github repo - https://github.com/Rushi-Unge/30Days30Projects.git

0
Subscribe to my newsletter

Read articles from Rushikesh Unge directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rushikesh Unge
Rushikesh Unge