You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
4.8 KiB

2 years ago
2 years ago
2 years ago
  1. import java.io.IOException;
  2. import java.io.InputStream;
  3. import java.io.OutputStream;
  4. import java.nio.charset.StandardCharsets;
  5. import java.util.Scanner;
  6. public class Vault implements VaultInterface {
  7. public boolean config;
  8. public int PWLength;
  9. public boolean haveCapitals;
  10. public boolean hasSpecialChars;
  11. public boolean hasNumbers;
  12. public boolean credentialM;
  13. public String userName;
  14. public String password;
  15. public boolean isInt = false;
  16. //InputStream inputS = System.in;
  17. OutputStream outputS = System.out;
  18. private void println(String output) {
  19. try {
  20. outputS.write((output + "\n").getBytes(StandardCharsets.UTF_8));
  21. } catch (IOException e) {
  22. e.printStackTrace();
  23. }
  24. }
  25. public void configure(){
  26. StringBuilder sbcm = new StringBuilder();
  27. Scanner scan = new Scanner(System.in);
  28. config = true;
  29. sbcm.append("Configure:\n");
  30. sbcm.append("- Password length: l\n");
  31. sbcm.append("- Have capitals: h\n");
  32. sbcm.append("- Have special characters: s\n");
  33. sbcm.append("- Have Numbers: n\n");
  34. sbcm.append("- exit: e\n");
  35. println(sbcm.toString());
  36. String input = scan.nextLine();
  37. if (input.equals("e")) {
  38. config = false;
  39. } else if (input.equals("l")) {
  40. println("Set PW length:");
  41. String inputPw = scan.nextLine();
  42. setPWLength(inputPw);
  43. } else if (input.equals("h")) {
  44. println("Should your PW have capitals? Type in yes or no.");
  45. String inputC = scan.nextLine();
  46. setCapital(inputC);
  47. } else if (input.equals("s")){
  48. println("Should you PW have special characters? Type in yes or no.");
  49. String inputS = scan.nextLine();
  50. setSpecialChar(inputS);
  51. } else if (input.equals("n")) {
  52. println("Should you PW have numbers? Type in yes or no.");
  53. String inputN = scan.nextLine();
  54. setNumbers(inputN);
  55. }
  56. }
  57. public void setPWLength(String pwLength){
  58. try {
  59. PWLength = Integer.parseInt(pwLength);
  60. } catch (NumberFormatException e) {
  61. println("Please enter valid number.");
  62. }
  63. println("\nNew password length is now: ");
  64. }
  65. public void addCredential(){
  66. Scanner scan = new Scanner(System.in);
  67. println("Type in username");
  68. userName = scan.nextLine();
  69. println("Type in password");
  70. password = scan.nextLine();
  71. //createNewCredential(userName, password);
  72. }
  73. public void showCredential(){
  74. Scanner scan = new Scanner(System.in);
  75. println("Type in ID or username");
  76. String str = scan.nextLine();
  77. if(str.matches("[0-9]+")) {
  78. isInt = true;
  79. //getCredentialsViaId(Integer.parseInt(str));
  80. } else {
  81. isInt = false;
  82. //getCredentialsViaName(str);
  83. }
  84. }
  85. public void getAsJson(){
  86. }
  87. public void loadFromJson(){
  88. }
  89. public void setCapital(String input) {
  90. if(input.equals("yes")){
  91. haveCapitals = true;
  92. println("Your PWs contain now capitals.");
  93. }else if(input.equals("no")){
  94. haveCapitals = false;
  95. println("Your PWs don´t have capitals anymore.");
  96. }
  97. }
  98. public void setSpecialChar(String input) {
  99. if(input.equals("yes")){
  100. hasSpecialChars = true;
  101. println("Your PWs contain now special characters.");
  102. }else if(input.equals("no")){
  103. hasSpecialChars = false;
  104. println("Your PWs don´t have special characters anymore.");
  105. }
  106. }
  107. public void setNumbers(String input) {
  108. if(input.equals("yes")){
  109. hasNumbers = true;
  110. println("Your PWs contains now numbers.");
  111. }else if(input.equals("no")){
  112. hasNumbers = false;
  113. println("Your PWs don´t have numbers anymore.");
  114. }
  115. }
  116. public void credentialMenu() {
  117. StringBuilder sbcm = new StringBuilder();
  118. Scanner scan = new Scanner(System.in);
  119. credentialM = true;
  120. sbcm.append("Configure credentials:\n");
  121. sbcm.append("- add credential: a\n");
  122. sbcm.append("- show credential: c\n");
  123. sbcm.append("- edit credential: l\n");
  124. sbcm.append("- exit: e\n");
  125. println(sbcm.toString());
  126. String input = scan.nextLine();
  127. if (input.equals("e")) {
  128. credentialM = false;
  129. } else if (input.equals("a")) {
  130. println("Type username:");
  131. } else if (input.equals("c")) {
  132. println("Type username or ID to show credential:");
  133. } else if (input.equals("l")) {
  134. println("Type username or ID to select credential:");
  135. }
  136. }
  137. }