0

Since yesterday, im working on a Program, that saves 1 password permanently, so its only for 1 time use. The saved password shall be printed by keyboard output later, thats why I thought, id start with an Array. Many people in other questions told me, that they would use ObjectArray or something like that. I am quite new to Java, thats why I would appreciate help. By the way, if you suggest something, id appreciate it, if its a bit more in depth. Here is the Code.

Robot bot = new Robot();
BufferedReader dmc = new BufferedReader(new InputStreamReader(System.in));

System.out.println("How many digits has your Password?");
String digit = dmc.readLine();
int d = Integer.parseInt(digit);
String[] password = new String[d];
System.out.println("Please enter your Password in single letters.");

int i = 0;
while (password[d - 1] == null) {
    password[i] = dmc.readLine();
    i++;
}

int j = 0;
while(j != d){
    password[j] = "KeyEvent.VK_" + password[j];
    j++;
}

poorly this doesn't work properly.

Sulthan
  • 128,090
  • 22
  • 218
  • 270
FunnyO
  • 383
  • 2
  • 20

1 Answers1

0

You should avoid storing passwords in Strings because of security reasons. You can read more here .

BufferedReader dmc = new BufferedReader(new InputStreamReader(System.in));

System.out.println("How many digits has your Password?");
String digit = dmc.readLine();
int d = Integer.parseInt(digit);
char[] password = new char[d];
System.out.println("Please enter your Password in single letters.");

dmc.read(password);

Stream.of(password).forEach(System.out::println);
Community
  • 1
  • 1
kukis
  • 4,489
  • 6
  • 27
  • 50
  • Thanks, that made it a bit easier, but I still cant print the password as keyboard output, as it is System.out.println, not KeyEvent. – FunnyO Nov 14 '15 at 14:03
  • What do you mean by "keyboard output" . Keyboard is a input device. – kukis Nov 14 '15 at 15:01
  • I mean, that with System.out.println, you only write in the command section, meaning it has no real effect, if you want to write something on another thread. For example, I have this code fully compiled and start a Program that needs an Password input. With System.out.Println it doesnt write anything, since its a System output. With a KeyEvent, it simulates a Keyboard input, so it writes something. I admit with "Keyboard output" its a bit confusing and wrong :D – FunnyO Nov 15 '15 at 09:13