Skip to content

Commit

Permalink
[ADD] Show password prompt if using GUI cmd line
Browse files Browse the repository at this point in the history
Show password prompt if using GUI cmd line, allows usage of `CREATE USER` in
GUI command line. Fixes BaseXdb#323.
  • Loading branch information
JensErat committed Dec 31, 2011
1 parent 390fc3c commit 5a622b2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
22 changes: 19 additions & 3 deletions src/main/java/org/basex/core/CommandParser.java
Expand Up @@ -68,6 +68,7 @@
import org.basex.core.cmd.ShowUsers;
import org.basex.core.cmd.Store;
import org.basex.core.cmd.XQuery;
import org.basex.gui.dialog.DialogPass;
import org.basex.io.IOFile;
import org.basex.query.QueryContext;
import org.basex.query.QueryException;
Expand All @@ -77,6 +78,7 @@
import org.basex.util.InputInfo;
import org.basex.util.InputParser;
import org.basex.util.Levenshtein;
import org.basex.util.Token;
import org.basex.util.Util;
import org.basex.util.list.StringList;

Expand Down Expand Up @@ -163,7 +165,7 @@ private Command parse(final Cmd cmd, final boolean s)
case INDEX:
return new CreateIndex(consume(CmdIndex.class, cmd));
case USER:
return new CreateUser(name(cmd), string(null));
return new CreateUser(name(cmd), password());
case EVENT:
return new CreateEvent(name(cmd));
}
Expand All @@ -175,7 +177,7 @@ private Command parse(final Cmd cmd, final boolean s)
case DATABASE: case DB:
return new AlterDB(name(cmd), name(cmd));
case USER:
return new AlterUser(name(cmd), string(null));
return new AlterUser(name(cmd), password());
}
break;
case OPEN:
Expand Down Expand Up @@ -253,7 +255,7 @@ private Command parse(final Cmd cmd, final boolean s)
case SET:
return new Set(name(cmd), string(null));
case PASSWORD:
return new Password(string(null));
return new Password(password());
case HELP:
String hc = name(null);
String form = null;
Expand Down Expand Up @@ -313,6 +315,20 @@ private Command parse(final Cmd cmd, final boolean s)
throw Util.notexpected("command specified, but not implemented yet");
}

/**
* Parses and returns a password.
* In command line and server mode, read from stdin, on GUI command line
* prompt using a password box.
* @return String md5-hashed password or empty string if cancelled
* @throws QueryException query exception
*/
protected String password() throws QueryException {
// gui -> gui autocompletion, Prop.gui -> BaseX in GUI mode
if (gui || !Prop.gui) return string(null);
final DialogPass dp = new DialogPass();
return dp.ok() ? Token.md5(dp.pass()) : "";
}

/**
* Parses and returns a string, delimited by a space or semicolon.
* Quotes can be used to include spaces.
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/basex/gui/dialog/DialogPass.java
Expand Up @@ -18,14 +18,21 @@
* @author BaseX Team 2005-11, BSD License
* @author Christian Gruen
*/
final class DialogPass extends Dialog {
public final class DialogPass extends Dialog {
/** New password. */
private final BaseXPassword pass;
/** Buttons. */
private final BaseXBack buttons;
/** Info label. */
private final BaseXLabel info;

/**
* Default constructor creating invisible frame as main window.
*/
public DialogPass() {
this(null);
}

/**
* Default constructor.
* @param main reference to the main window
Expand Down Expand Up @@ -72,7 +79,7 @@ public void close() {
* Returns the password.
* @return password
*/
String pass() {
public String pass() {
return new String(pass.getPassword());
}
}

0 comments on commit 5a622b2

Please sign in to comment.