|
|
@ -17,17 +17,15 @@ public class Vault implements VaultInterface { |
|
|
|
public int newID; |
|
|
|
public String newString; |
|
|
|
public boolean decision; |
|
|
|
public boolean isInt = false; |
|
|
|
|
|
|
|
InputStream inputS = System.in; |
|
|
|
OutputStream outputS = System.out; |
|
|
|
|
|
|
|
private CredentialRepository credentialRepository = new CredentialRepository(); |
|
|
|
|
|
|
|
public static void main (String args[]) { |
|
|
|
/*public static void main (String args[]) { |
|
|
|
Vault vault = new Vault(); |
|
|
|
vault.credentialMenu(); |
|
|
|
} |
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
private void println(String output) { |
|
|
@ -54,24 +52,34 @@ public class Vault implements VaultInterface { |
|
|
|
|
|
|
|
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(inputN); |
|
|
|
switch(input) { |
|
|
|
case "e": |
|
|
|
config = false; |
|
|
|
break; |
|
|
|
|
|
|
|
case "l": |
|
|
|
println("Set PW length:"); |
|
|
|
String inputPw = scan.nextLine(); |
|
|
|
setPWLength(inputPw); |
|
|
|
break; |
|
|
|
|
|
|
|
case "h": |
|
|
|
println("Should your PW have capitals? Type in yes or no."); |
|
|
|
String inputC = scan.nextLine(); |
|
|
|
setCapital(inputC); |
|
|
|
break; |
|
|
|
|
|
|
|
case "s": |
|
|
|
println("Should you PW have special characters? Type in yes or no."); |
|
|
|
String inputS = scan.nextLine(); |
|
|
|
setSpecialChar(inputS); |
|
|
|
break; |
|
|
|
|
|
|
|
case "n": |
|
|
|
println("Should you PW have numbers? Type in yes or no."); |
|
|
|
String inputN = scan.nextLine(); |
|
|
|
setNumbers(inputN); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -86,11 +94,22 @@ public class Vault implements VaultInterface { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void addCredential(String userName, String password){ |
|
|
|
public void addCredential(){ |
|
|
|
Scanner scan = new Scanner(inputS); |
|
|
|
println("Type in username"); |
|
|
|
userName = scan.nextLine(); |
|
|
|
|
|
|
|
println("Type in password"); |
|
|
|
password = scan.nextLine(); |
|
|
|
credentialRepository.createNewCredential(userName, password); |
|
|
|
} |
|
|
|
|
|
|
|
public void showCredential(String str) { |
|
|
|
public void showCredential() { |
|
|
|
Scanner scan = new Scanner(inputS); |
|
|
|
println("Type in ID or username"); |
|
|
|
|
|
|
|
String str = scan.nextLine(); |
|
|
|
|
|
|
|
if(str.matches("[0-9]+")) { |
|
|
|
println("Getting credential via ID"); |
|
|
|
credentialRepository.getCredentialsViaId(Integer.parseInt(str)); |
|
|
@ -101,6 +120,35 @@ public class Vault implements VaultInterface { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void editCredential() { |
|
|
|
Scanner scan = new Scanner(inputS); |
|
|
|
|
|
|
|
println("Type ID to select credential:"); |
|
|
|
newID = Integer.parseInt(scan.nextLine()); |
|
|
|
|
|
|
|
println("-change username: u\n-change password: p"); |
|
|
|
|
|
|
|
String input = scan.nextLine(); |
|
|
|
|
|
|
|
if (input.equals("u")) { |
|
|
|
decision = true; |
|
|
|
} |
|
|
|
|
|
|
|
if(decision){ |
|
|
|
|
|
|
|
println("Type new username:"); |
|
|
|
newString = scan.nextLine(); |
|
|
|
|
|
|
|
credentialRepository.updateUsername(newID, newString); |
|
|
|
} else { |
|
|
|
|
|
|
|
println("Type new password:"); |
|
|
|
newString = scan.nextLine(); |
|
|
|
|
|
|
|
credentialRepository.updatePassword(newID, newString); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void getAsJson(){ |
|
|
|
|
|
|
@ -117,7 +165,7 @@ public class Vault implements VaultInterface { |
|
|
|
println("Your PWs contain now capitals."); |
|
|
|
}else if(input.equals("no")){ |
|
|
|
haveCapitals = false; |
|
|
|
println("Your PWs don't have capitals anymore."); |
|
|
|
println("Your PWs don´t have capitals anymore."); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -129,7 +177,7 @@ public class Vault implements VaultInterface { |
|
|
|
println("Your PWs contain now special characters."); |
|
|
|
}else if(input.equals("no")){ |
|
|
|
hasSpecialChars = false; |
|
|
|
println("Your PWs don't have special characters anymore."); |
|
|
|
println("Your PWs don´t have special characters anymore."); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -140,7 +188,7 @@ public class Vault implements VaultInterface { |
|
|
|
println("Your PWs contains now numbers."); |
|
|
|
}else if(input.equals("no")){ |
|
|
|
hasNumbers = false; |
|
|
|
println("Your PWs don't have numbers anymore."); |
|
|
|
println("Your PWs don´t have numbers anymore."); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -159,40 +207,23 @@ public class Vault implements VaultInterface { |
|
|
|
|
|
|
|
String input = scan.nextLine(); |
|
|
|
|
|
|
|
switch(input) { |
|
|
|
case "e": |
|
|
|
credentialM = false; |
|
|
|
break; |
|
|
|
|
|
|
|
if (input.equals("e")) { |
|
|
|
credentialM = false; |
|
|
|
} |
|
|
|
|
|
|
|
if (input.equals("a")) { |
|
|
|
println("Type in username"); |
|
|
|
userName = scan.nextLine(); |
|
|
|
|
|
|
|
println("Type in password"); |
|
|
|
password = scan.nextLine(); |
|
|
|
addCredential(userName, password); |
|
|
|
} |
|
|
|
|
|
|
|
if (input.equals("c")) { |
|
|
|
println("Type in ID or username"); |
|
|
|
case "a": |
|
|
|
println("Add credential:"); |
|
|
|
addCredential(); |
|
|
|
break; |
|
|
|
|
|
|
|
String str = scan.nextLine(); |
|
|
|
showCredential(str); |
|
|
|
case "c": |
|
|
|
showCredential(); |
|
|
|
break; |
|
|
|
|
|
|
|
} else if (input.equals("l")) { |
|
|
|
println("Type ID to select credential:"); |
|
|
|
newID = Integer.parseInt(scan.nextLine()); |
|
|
|
println("-change username: u\n-change password: p"); |
|
|
|
input = scan.nextLine(); |
|
|
|
|
|
|
|
if (input.equals("u")) { |
|
|
|
decision = true; |
|
|
|
}else{ |
|
|
|
decision = false; |
|
|
|
} |
|
|
|
println("Type new:"); |
|
|
|
newString = scan.nextLine(); |
|
|
|
//editCredential(newID, newString, decision); |
|
|
|
case "l": |
|
|
|
editCredential(); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |