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.

128 lines
3.3 KiB

  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("- exit: e\n");
  30. println(sbcm.toString());
  31. String input = scan.nextLine();
  32. if (input.equals("e")) {
  33. config = false;
  34. } else if (input.equals("l")) {
  35. println("Set PW length:");
  36. String inputPw = scan.nextLine();
  37. setPWLength(inputPw);
  38. } else if (input.equals("h")) {
  39. println("Should your PW have capitals? Type in yes or no.");
  40. String inputC = scan.nextLine();
  41. setPWLength(inputC);
  42. }
  43. }
  44. public void setPWLength(String pwLength){
  45. try {
  46. PWLength = Integer.parseInt(pwLength);
  47. } catch (NumberFormatException e) {
  48. println("Please Enter Valid Number.");
  49. }
  50. println("\nNew PWlength is now: ");
  51. }
  52. public void addCredential(){
  53. println("Add user name");
  54. Scanner scan = new Scanner(inputS);
  55. String input = scan.nextLine();
  56. userName = input;
  57. }
  58. public void showCredential(){
  59. }
  60. public void getAsJson(){
  61. }
  62. public void loadFromJson(){
  63. }
  64. public void setCapital(String input) {
  65. if(input.equals("yes")){
  66. haveCapitals = true;
  67. println("Your PWs contain now capitals.");
  68. }else if(input.equals("no")){
  69. haveCapitals = false;
  70. println("Your PWs don´t have capitals anymore.");
  71. }
  72. }
  73. public void setSpecialChar() {
  74. println("Should you PW have special characters? Type in yes or no.");
  75. Scanner scan = new Scanner(inputS);
  76. String input = scan.nextLine();
  77. if(input.equals("yes")){
  78. hasSpecialChars = true;
  79. println("Your PWs contain now special characters.");
  80. }else if(input.equals("no")){
  81. hasSpecialChars = false;
  82. println("Your PWs don´t have special characters anymore.");
  83. }
  84. }
  85. public void SetNumbers() {
  86. println("Should you PW have numbers? Type in yes or no.");
  87. Scanner scan = new Scanner(inputS);
  88. String input = scan.nextLine();
  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. }