From cdf564025c65a6876350f07e10183079f02f89e3 Mon Sep 17 00:00:00 2001 From: coderzc Date: Mon, 22 Mar 2021 14:34:26 +0800 Subject: [PATCH 1/2] auth fix: init store password must be not empty --- .../hugegraph/auth/StandardAuthenticator.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) 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..315183e6a3 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,17 +65,25 @@ private void initAdminUser() throws Exception { } private String inputPassword() { + String password = ""; String prompt = "Please input the admin password:"; + String alertMsg = "password must be not 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(); - } + do { + if (console != null) { + char[] chars = console.readPassword(prompt); + password = new String(chars); + } else { + System.out.print(prompt); + @SuppressWarnings("resource") // just wrapper of System.in + Scanner scanner = new Scanner(System.in); + password = scanner.nextLine(); + } + if (password.isEmpty()) { + System.out.println(alertMsg); + } + } while (password.isEmpty()); + return password; } @Override From 8425915cdc541a0070809bcf1b30692dbce7e36f Mon Sep 17 00:00:00 2001 From: coderzc Date: Mon, 22 Mar 2021 15:01:54 +0800 Subject: [PATCH 2/2] auth fix: init store the admin password can't be empty --- .../hugegraph/auth/StandardAuthenticator.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) 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 315183e6a3..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,25 +65,25 @@ private void initAdminUser() throws Exception { } private String inputPassword() { - String password = ""; - String prompt = "Please input the admin password:"; - String alertMsg = "password must be not empty"; + String inputPrompt = "Please input the admin password:"; + String notEmptyPrompt = "The admin password can't be empty"; Console console = System.console(); - do { + while (true) { + String password = ""; if (console != null) { - char[] chars = console.readPassword(prompt); + char[] chars = console.readPassword(inputPrompt); password = new String(chars); } else { - System.out.print(prompt); + System.out.print(inputPrompt); @SuppressWarnings("resource") // just wrapper of System.in Scanner scanner = new Scanner(System.in); password = scanner.nextLine(); } - if (password.isEmpty()) { - System.out.println(alertMsg); + if (!password.isEmpty()) { + return password; } - } while (password.isEmpty()); - return password; + System.out.println(notEmptyPrompt); + } } @Override