From 2d1961941a1f9daf490c638aa2254b8273bfd3f4 Mon Sep 17 00:00:00 2001 From: Bluenzo <80460870+Bluenzo@users.noreply.github.com> Date: Wed, 9 Apr 2025 11:09:37 -0700 Subject: [PATCH 1/3] hardcoded password and printed it --- src/PasswordApp.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/PasswordApp.java b/src/PasswordApp.java index 86fb0b1..6b6c26a 100644 --- a/src/PasswordApp.java +++ b/src/PasswordApp.java @@ -1,5 +1,10 @@ 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 d6f8aadddbcf376431b046b43d981682d9ededda Mon Sep 17 00:00:00 2001 From: Bluenzo <80460870+Bluenzo@users.noreply.github.com> Date: Wed, 9 Apr 2025 11:25:28 -0700 Subject: [PATCH 2/3] I added an user input --- src/PasswordApp.java | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/PasswordApp.java b/src/PasswordApp.java index 6b6c26a..b99a784 100644 --- a/src/PasswordApp.java +++ b/src/PasswordApp.java @@ -1,10 +1,28 @@ +// javac ....the file name of your Java source code file && java -cp src ..javaname... to print in the terminal +import java.util.Scanner; // Import the Scanner class to use Scanner public class PasswordApp { public static void main(String[] args) { + // Create a Scanner object to read user input + Scanner scanner = new Scanner(System.in); + System.out.println("Welcome to the password checker!"); - - String password = "hello123"; + + // Read the password from the user input + String password = scanner.nextLine(); + System.out.println("The password is: " + (password)); + + //To find the length of the password + //password.length() + if(password.length() >= 12){ + System.out.println("Your password is long enough."); + }else{ + System.out.println("Your password is not long enough."); + } + + //Scanner needs to be closed to free up resources + scanner.close(); } } \ No newline at end of file From 3f5fd9f0cbbf049e92e731ba01c1241dee8db739 Mon Sep 17 00:00:00 2001 From: Bluenzo <80460870+Bluenzo@users.noreply.github.com> Date: Wed, 9 Apr 2025 11:51:03 -0700 Subject: [PATCH 3/3] Support for multiple password --- src/PasswordApp.java | 55 +++++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/src/PasswordApp.java b/src/PasswordApp.java index b99a784..a4ae483 100644 --- a/src/PasswordApp.java +++ b/src/PasswordApp.java @@ -1,4 +1,6 @@ // javac ....the file name of your Java source code file && java -cp src ..javaname... to print in the terminal +// add < ...file name... > in your terminal to compile your Java file and then run it with the command java -cp src Main + import java.util.Scanner; // Import the Scanner class to use Scanner public class PasswordApp { public static void main(String[] args) { @@ -7,19 +9,46 @@ public static void main(String[] args) { System.out.println("Welcome to the password checker!"); - // Read the password from the user input - String password = scanner.nextLine(); - - - System.out.println("The password is: " + (password)); - - //To find the length of the password - //password.length() - if(password.length() >= 12){ - System.out.println("Your password is long enough."); - }else{ - System.out.println("Your password is not long enough."); - } + // Read user input until there is no more input + while(scanner.hasNextLine()){ + + // Read the password from the user input + String password = scanner.nextLine(); + + + System.out.println("The password is: " + (password)); + + //To find the length of the password + //password.length() + if(password.length() >= 12){ + System.out.println("Your password is long enough."); + }else{ + System.out.println("Your password is not long enough."); + } + + // toCharArray() method is used to convert a string into a character array. + char [] characters = password.toCharArray(); + + boolean hasSpecialChar = false; // Flag to check if the password has a special character + + // Using a for loop to iterate over each character in the array + for (int i =0; i < characters.length; i++) { + char character = characters[i]; // Get the current character from the array + // System.out.println(Character.isAlphabetic(character)); // Check if the character is alphabetic, true if it is, false otherwise + + // Check if the character is not alphabetic (not a letter) + if(Character.isAlphabetic(character) == false){ + hasSpecialChar = true; + } + } + + System.out.println("Has a special character: " + hasSpecialChar); + } + + + + + //Scanner needs to be closed to free up resources scanner.close();