diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/StandardAuthenticator.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/StandardAuthenticator.java index 6f2f8f7507..c343a424f8 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/StandardAuthenticator.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/StandardAuthenticator.java @@ -65,16 +65,24 @@ private void initAdminUser() throws Exception { } private String inputPassword() { - String prompt = "Please input the admin password:"; + String inputPrompt = "Please input the admin password:"; + String notEmptyPrompt = "The admin password can't be empty"; Console console = System.console(); - if (console != null) { - char[] chars = console.readPassword(prompt); - return new String(chars); - } else { - System.out.print(prompt); - @SuppressWarnings("resource") // just wrapper of System.in - Scanner scanner = new Scanner(System.in); - return scanner.nextLine(); + while (true) { + String password = ""; + if (console != null) { + char[] chars = console.readPassword(inputPrompt); + password = new String(chars); + } else { + System.out.print(inputPrompt); + @SuppressWarnings("resource") // just wrapper of System.in + Scanner scanner = new Scanner(System.in); + password = scanner.nextLine(); + } + if (!password.isEmpty()) { + return password; + } + System.out.println(notEmptyPrompt); } }