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.

134 lines
3.6 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 String userName;
  13. InputStream inputS = System.in;
  14. OutputStream outputS = System.out;
  15. private void println(String output) {
  16. try {
  17. outputS.write((output + "\n").getBytes(StandardCharsets.UTF_8));
  18. } catch (IOException e) {
  19. e.printStackTrace();
  20. }
  21. }
  22. public void configure(){
  23. StringBuilder sbcm = new StringBuilder();
  24. Scanner scan = new Scanner(inputS);
  25. config = true;
  26. sbcm.append("Configure:\n");
  27. sbcm.append("- Password length: l\n");
  28. sbcm.append("- Have capitals: h\n");
  29. sbcm.append("- Have special characters: s\n");
  30. sbcm.append("- Have Numbers: n\n");
  31. sbcm.append("- exit: e\n");
  32. println(sbcm.toString());
  33. String input = scan.nextLine();
  34. if (input.equals("e")) {
  35. config = false;
  36. } else if (input.equals("l")) {
  37. println("Set PW length:");
  38. String inputPw = scan.nextLine();
  39. setPWLength(inputPw);
  40. } else if (input.equals("h")) {
  41. println("Should your PW have capitals? Type in yes or no.");
  42. String inputC = scan.nextLine();
  43. setCapital(inputC);
  44. } else if (input.equals("s")){
  45. println("Should you PW have special characters? Type in yes or no.");
  46. String inputS = scan.nextLine();
  47. setSpecialChar(inputS);
  48. } else if (input.equals("n")) {
  49. println("Should you PW have numbers? Type in yes or no.");
  50. String inputN = scan.nextLine();
  51. setNumbers(input);
  52. }
  53. }
  54. public void setPWLength(String pwLength){
  55. try {
  56. PWLength = Integer.parseInt(pwLength);
  57. } catch (NumberFormatException e) {
  58. println("Please enter valid number.");
  59. }
  60. println("\nNew password length is now: ");
  61. }
  62. public void addCredential(){
  63. }
  64. public void showCredential(){
  65. }
  66. public void getAsJson(){
  67. }
  68. public void loadFromJson(){
  69. }
  70. public void setCapital(String input) {
  71. if(input.equals("yes")){
  72. haveCapitals = true;
  73. println("Your PWs contain now capitals.");
  74. }else if(input.equals("no")){
  75. haveCapitals = false;
  76. println("Your PWs don´t have capitals anymore.");
  77. }
  78. }
  79. public void setSpecialChar(String input) {
  80. if(input.equals("yes")){
  81. hasSpecialChars = true;
  82. println("Your PWs contain now special characters.");
  83. }else if(input.equals("no")){
  84. hasSpecialChars = false;
  85. println("Your PWs don´t have special characters anymore.");
  86. }
  87. }
  88. public void setNumbers(String input) {
  89. if(input.equals("yes")){
  90. hasNumbers = true;
  91. println("Your PWs contains now numbers.");
  92. }else if(input.equals("no")){
  93. hasNumbers = false;
  94. println("Your PWs don´t have numbers anymore.");
  95. }
  96. }
  97. public void credentialMenu() {
  98. StringBuilder sbcm = new StringBuilder();
  99. sbcm.append("Configure credentials:\n");
  100. sbcm.append("- add credential: a\n");
  101. sbcm.append("- show credential: c\n");
  102. sbcm.append("- exit: e\n");
  103. println(sbcm.toString());
  104. }
  105. }