Skip to content

Commit fc98918

Browse files
committed
Prompt for DB password on initial startup
Added prompt to set DB password on initial startup
1 parent 38828a1 commit fc98918

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/main/java/com/keybox/common/db/DBInitServlet.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,24 @@ public void init(ServletConfig config) throws ServletException {
6565

6666
//if DB password is empty generate a random
6767
if(StringUtils.isEmpty(AppConfig.getProperty("dbPassword"))) {
68-
AppConfig.encryptProperty("dbPassword", RandomStringUtils.randomAscii(32));
68+
String dbPassword = null;
69+
String dbPasswordConfirm = null;
70+
//prompt for password and confirmation
71+
while (dbPassword == null || !dbPassword.equals(dbPasswordConfirm)) {
72+
dbPassword = new String(System.console().readPassword("Please enter database password: "));
73+
dbPasswordConfirm = new String(System.console().readPassword("Please confirm database password: "));
74+
if(!dbPassword.equals(dbPasswordConfirm)) {
75+
System.out.println("Passwords do not match");
76+
}
77+
}
78+
//set password
79+
if(StringUtils.isNotEmpty(dbPassword)) {
80+
AppConfig.encryptProperty("dbPassword", dbPassword);
81+
//if password not set generate a random
82+
} else {
83+
System.out.println("Generating random database password");
84+
AppConfig.encryptProperty("dbPassword", RandomStringUtils.randomAscii(32));
85+
}
6986
//else encrypt password if plain-text
7087
} else if (!AppConfig.isPropertyEncrypted("dbPassword")) {
7188
AppConfig.encryptProperty("dbPassword", AppConfig.getProperty("dbPassword"));

0 commit comments

Comments
 (0)