Skip to content

Commit 82b0d54

Browse files
author
James Williams
authored
Mandate password prompt for user creation (#195)
## What is the goal of this PR? We now force passwords to be entered in a password prompt. This prevents passwords from showing up in the command history. ## What are the changes implemented in this PR? We've changed the flow of the user create command. Now, when creating a user, you supply a username and are then prompted to supply a password separately.
1 parent 28e3ada commit 82b0d54

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

TypeDBConsole.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.vaticle.typedb.console.command.REPLCommand;
3737
import com.vaticle.typedb.console.command.TransactionREPLCommand;
3838
import com.vaticle.typedb.console.common.Printer;
39+
import com.vaticle.typedb.console.common.Utils;
3940
import com.vaticle.typedb.console.common.exception.TypeDBConsoleException;
4041
import com.vaticle.typeql.lang.TypeQL;
4142
import com.vaticle.typeql.lang.common.TypeQLArg;
@@ -771,7 +772,7 @@ private static class CLIOptions implements Runnable {
771772
@CommandLine.Option(
772773
names = {"--password"},
773774
description = "Password",
774-
prompt = "Enter password:",
775+
prompt = "Password: ",
775776
interactive = true,
776777
arity = "0..1"
777778
)

command/REPLCommand.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ public User.List asUserList() {
341341
public static class Create extends REPLCommand.User {
342342

343343
public static String token = "create";
344-
private static String helpCommand = User.token + " " + token + " " + "<username> <password>";
345-
private static String description = "Create a user with name <username> and password <password> on the server";
344+
private static String helpCommand = User.token + " " + token + " " + "<username>";
345+
private static String description = "Create a user with name <username> and a supplied password on the server";
346346

347347
private final String user;
348348
private final String password;
@@ -673,15 +673,10 @@ static REPLCommand readREPLCommand(String line, @Nullable LineReader passwordRea
673673
}
674674
else if (tokens.length == 2 && tokens[0].equals(User.token) && tokens[1].equals(User.List.token)) {
675675
command = new User.List();
676-
} else if ((tokens.length == 3 || tokens.length == 4) && tokens[0].equals(User.token) && tokens[1].equals(User.Create.token)) {
676+
} else if (tokens.length == 3 && tokens[0].equals(User.token) && tokens[1].equals(User.Create.token)) {
677677
String name = tokens[2];
678-
String password;
679-
if (tokens.length == 3) {
680-
if (passwordReader == null) throw new TypeDBConsoleException(UNABLE_TO_READ_PASSWORD_INTERACTIVELY);
681-
password = Utils.readPassword(passwordReader, "Enter password:");
682-
} else {
683-
password = tokens[3];
684-
}
678+
if (passwordReader == null) throw new TypeDBConsoleException(UNABLE_TO_READ_PASSWORD_INTERACTIVELY);
679+
String password = Utils.readPassword(passwordReader, "Password: ");
685680
command = new User.Create(name, password);
686681
} else if (tokens.length == 3 && tokens[0].equals(User.token) && tokens[1].equals(User.Delete.token)) {
687682
String name = tokens[2];

common/Utils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static String readNonEmptyLine(LineReader reader, String prompt) throws I
7373
}
7474

7575
public static String readPassword(LineReader passwordReader, String prompt) {
76-
return passwordReader.readLine(prompt, (char) 0);
76+
return passwordReader.readLine(prompt, '*');
7777
}
7878

7979
public static String getContinuationPrompt(String prompt) {

0 commit comments

Comments
 (0)