import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.StandardCharsets; import java.util.Scanner; public class Vault implements VaultInterface { public boolean config; public int PWLength; public boolean haveCapitals; public boolean hasSpecialChars; public boolean hasNumbers; public String userName; InputStream inputS = System.in; OutputStream outputS = System.out; private void println(String output) { try { outputS.write((output + "\n").getBytes(StandardCharsets.UTF_8)); } catch (IOException e) { e.printStackTrace(); } } public void configure(){ StringBuilder sbcm = new StringBuilder(); Scanner scan = new Scanner(inputS); config = true; sbcm.append("Configure:\n"); sbcm.append("- Password length: l\n"); sbcm.append("- Have capitals: h\n"); sbcm.append("- Have special characters: s\n"); sbcm.append("- Have Numbers: n\n"); sbcm.append("- exit: e\n"); println(sbcm.toString()); String input = scan.nextLine(); if (input.equals("e")) { config = false; } else if (input.equals("l")) { println("Set PW length:"); String inputPw = scan.nextLine(); setPWLength(inputPw); } else if (input.equals("h")) { println("Should your PW have capitals? Type in yes or no."); String inputC = scan.nextLine(); setCapital(inputC); } else if (input.equals("s")){ println("Should you PW have special characters? Type in yes or no."); String inputS = scan.nextLine(); setSpecialChar(inputS); } else if (input.equals("n")) { println("Should you PW have numbers? Type in yes or no."); String inputN = scan.nextLine(); setNumbers(input); } } public void setPWLength(String pwLength){ try { PWLength = Integer.parseInt(pwLength); } catch (NumberFormatException e) { println("Please enter valid number."); } println("\nNew password length is now: "); } public void addCredential(){ } public void showCredential(){ } public void getAsJson(){ } public void loadFromJson(){ } public void setCapital(String input) { if(input.equals("yes")){ haveCapitals = true; println("Your PWs contain now capitals."); }else if(input.equals("no")){ haveCapitals = false; println("Your PWs don´t have capitals anymore."); } } public void setSpecialChar(String input) { if(input.equals("yes")){ hasSpecialChars = true; println("Your PWs contain now special characters."); }else if(input.equals("no")){ hasSpecialChars = false; println("Your PWs don´t have special characters anymore."); } } public void setNumbers(String input) { if(input.equals("yes")){ hasNumbers = true; println("Your PWs contains now numbers."); }else if(input.equals("no")){ hasNumbers = false; println("Your PWs don´t have numbers anymore."); } } public void credentialMenu() { StringBuilder sbcm = new StringBuilder(); sbcm.append("Configure credentials:\n"); sbcm.append("- add credential: a\n"); sbcm.append("- show credential: c\n"); sbcm.append("- exit: e\n"); println(sbcm.toString()); } }