1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package com.gridsystems.config.tools.console;
25
26 import java.io.IOException;
27 import java.text.MessageFormat;
28 import java.util.ResourceBundle;
29
30
31
32
33
34
35
36 public class PasswordField extends ValueField {
37
38
39
40
41 private static ResourceBundle bundle = ResourceBundle.getBundle("config");
42
43
44
45
46
47
48
49 public PasswordField(ResourceBundle bundle, String linePattern) {
50 super(bundle, linePattern, null);
51 }
52
53
54
55
56 public String[] getContents() {
57 String[] contents = new String[1];
58
59
60 StringBuffer pattern = new StringBuffer();
61 String key = getKeyMapping();
62 if (key != null) {
63 pattern.append(" ").append(key).append(". ");
64 }
65
66 pattern.append(getString(linePattern));
67
68 String s = getStringValue();
69 int count = s.length();
70 s = "*********************************************".substring(0, count);
71
72 contents[0] = MessageFormat.format(pattern.toString(), new Object[] { s });
73 return contents;
74 }
75
76
77
78
79
80
81
82 protected String readLine() throws IOException {
83 String prompt;
84
85 do {
86 prompt = bundle.getString("console.typepassword");
87 String pass1 = ConsoleTools.readPassword(prompt, '*');
88 prompt = bundle.getString("console.retypepassword");
89 String pass2 = ConsoleTools.readPassword(prompt, '*');
90
91 if (pass1.equals(pass2)) {
92 return pass1;
93 } else {
94 System.out.println("ERROR: Passwords do not match");
95 }
96 } while (true);
97 }
98
99 }