Day 3 - PassGuard | #30Days30Projects

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
manipulationPattern
andMatcher
classes fromjava.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
Create the folder structure:
mkdir -p PassGuard/src cd PassGuard/src touch PassGuard.java
Paste the code in
PassGuard.java
.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
Subscribe to my newsletter
Read articles from Rushikesh Unge directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
