From dd6df1fdd20a01cc2784c513ef35797517c1a6e3 Mon Sep 17 00:00:00 2001 From: sandeersson Date: Wed, 9 Apr 2025 11:09:32 -0700 Subject: [PATCH 1/3] hardcoded password and printed it --- src/PasswordApp.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/PasswordApp.java b/src/PasswordApp.java index 86fb0b1..63544cb 100644 --- a/src/PasswordApp.java +++ b/src/PasswordApp.java @@ -1,5 +1,9 @@ public class PasswordApp { public static void main(String[] args) { System.out.println("Welcome to the password checker!"); + + String password = "hello123"; + + System.out.println("The password is: " + password); } } \ No newline at end of file From 9caa5abbe6b11a99552f723b1cb5e6523a5b5775 Mon Sep 17 00:00:00 2001 From: sandeersson Date: Wed, 9 Apr 2025 11:23:53 -0700 Subject: [PATCH 2/3] user input for password --- src/PasswordApp.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/PasswordApp.java b/src/PasswordApp.java index 63544cb..3856c27 100644 --- a/src/PasswordApp.java +++ b/src/PasswordApp.java @@ -1,9 +1,19 @@ +import java.util.Scanner; + public class PasswordApp { public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + System.out.println("Welcome to the password checker!"); - String password = "hello123"; + String password = scanner.nextLine(); System.out.println("The password is: " + password); + + if (password.length() >= 12){ + System.out.println("Your password is a good length!"); + } else { + System.out.println("Your password is too short"); + } } } \ No newline at end of file From 0c044a8bb51361dafebb7d1bc4236e4c3a3168ac Mon Sep 17 00:00:00 2001 From: sandeersson Date: Wed, 9 Apr 2025 11:51:04 -0700 Subject: [PATCH 3/3] support for multiple passwords --- src/PasswordApp.java | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/PasswordApp.java b/src/PasswordApp.java index 3856c27..40733a3 100644 --- a/src/PasswordApp.java +++ b/src/PasswordApp.java @@ -6,14 +6,28 @@ public static void main(String[] args) { System.out.println("Welcome to the password checker!"); - String password = scanner.nextLine(); + while (scanner.hasNextLine()) { + String password = scanner.nextLine(); - System.out.println("The password is: " + password); + System.out.println("The password is: " + password); - if (password.length() >= 12){ - System.out.println("Your password is a good length!"); - } else { - System.out.println("Your password is too short"); + if (password.length() >= 12) { + System.out.println("Your password is a good length!"); + } else { + System.out.println("Your password is too short"); + } + + char[] characters = password.toCharArray(); + + boolean hasSpecial = false; + + for (int i = 0; i < characters.length; i++) { + char character = characters[i]; + if (Character.isAlphabetic(character) == false) { + hasSpecial = true; + } + } + System.out.println("Has a special character " + hasSpecial); } } } \ No newline at end of file