This code is supposed to be a password checker that adds the password to an array once it fits into the requirements which checking to see if its been added previously. If it has been added before, it tells you and doesn't add it. BUT it only does this for the first password that has been inputted. I'm pretty new to coding, so any help is greatly appreciated.
This code is supposed to be a password checker that adds the password to an array once it fits into the requirements which checking to see if its been added previously. If it has been added before, it tells you and doesn't add it. BUT it only does this for the first password that has been inputted. I'm pretty new to coding, so any help is greatly appreciated.import java.util.Scanner; class Main { public static void main(String[] args) { System.out.print("\033[H\033[2J"); String password; String[]Rpassword = {null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null}; int yo = 0, count; while(yo <= 20){{ int sum = 0; int min = 7; int digit = 0; int Upper = 0; int Lower = 0; System.out.println(); Scanner scan = new Scanner(System.in); System.out.println("Enter Your Password: "); password = scan.nextLine(); if (password.length() < min) { System.out.println("Your password is under 7 charcters"); }else{ char c; for (int i = 0; i < password.length(); i++) { c = password.charAt(i); if(Character.isUpperCase(c)){ Upper++;} if(Character.isLowerCase(c)){ Lower++;} if(Character.isDigit(c)){ digit++;} } sum = Upper + Lower + digit; if (password.length() != sum){ System.out.println("Please remove a special character from your password and try again"); }else if (!(Upper >= 1 )){ System.out.println("Please add at least one uppercase letter to your password and try again"); }else if (!(Lower >= 1 )){ System.out.println("Please add at least one lowercase letter to your password and try again"); }else if (!(digit >= 1 )){ System.out.println("Please add at least one number to your password and try again"); }else{ System.out.println("Your password fits all categories! "); for (int d = 0; d < Rpassword.length; d++) { if (password.equals(Rpassword[d])){ //if (Rpassword[d].equals(password)){ System.out.println("This password was already said, input another one"); break; }else{ Rpassword[yo] = password; System.out.println("Your password is stored in the " + yo + " space"); yo = yo + 1; break;}} } } } } }}
import java.util.Scanner; class Main { public static void main(String[] args) { System.out.print("\033[H\033[2J"); String password; String[]Rpassword = {null,null,null,null,null,null,null,null,null,null ,null,null,null,null,null,null,null,null,null,null ,null}; int yo = 0, count; while(yo <= 20){{ int sum = 0; int min = 7; int digit = 0; int Upper = 0; int Lower = 0; System.out.println(); Scanner scan = new Scanner(System.in); System.out.println("Enter Your Password: "); password = scan.nextLine(); if (password.length() < min) { System.out.println("Your password is under 7 charcters"); }else{ char c; for (int i = 0; i < password.length(); i++) { c = password.charAt(i); if(Character.isUpperCase(c)){ Upper++;} if(Character.isLowerCase(c)){ Lower++;} if(Character.isDigit(c)){ digit++;} } sum = Upper + Lower + digit; if (password.length() != sum){ System.out.println("Please remove a special character from your password and try again"); }else if (!(Upper >= 1 )){ System.out.println("Please add at least one uppercase letter to your password and try again"); }else if (!(Lower >= 1 )){ System.out.println("Please add at least one lowercase letter to your password and try again"); }else if (!(digit >= 1 )){ System.out.println("Please add at least one number to your password and try again"); }else{ System.out.println("Your password fits all categories! "); for (int d = 0; d < Rpassword.length; d++) { if (password.equals(Rpassword[d])){ //if (Rpassword[d].equals(password)){ System.out.println("This password was already said, input another one"); break; }else{ Rpassword[yo] = password; System.out.println("Your password is stored in the " + yo + " space"); yo = yo + 1; break;}} } } } } }}