-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #9556 - Better prompt for input on Password #9557
Changes from 5 commits
f6f58b5
2d71152
95bd40c
7366465
411de6a
7a861ae
c1ec980
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -13,10 +13,14 @@ | |||||
|
||||||
package org.eclipse.jetty.util.security; | ||||||
|
||||||
import java.io.BufferedReader; | ||||||
import java.io.IOException; | ||||||
import java.io.InputStreamReader; | ||||||
import java.nio.charset.StandardCharsets; | ||||||
import java.util.Locale; | ||||||
|
||||||
import org.eclipse.jetty.util.StringUtil; | ||||||
|
||||||
/** | ||||||
* Password utility class. | ||||||
* | ||||||
|
@@ -230,21 +234,76 @@ public static Password getPassword(String realm, String dft, String promptDft) | |||||
return new Password(passwd); | ||||||
} | ||||||
|
||||||
public static void main(String[] arg) | ||||||
public static void main(String[] args) throws IOException | ||||||
{ | ||||||
if (arg.length != 1 && arg.length != 2) | ||||||
boolean promptUser = false; | ||||||
String argUser = null; | ||||||
String argPassword = null; | ||||||
|
||||||
for (String arg: args) | ||||||
{ | ||||||
if (arg.equals("--prompt")) | ||||||
{ | ||||||
promptUser = true; | ||||||
// ignore any other args | ||||||
break; | ||||||
} | ||||||
|
||||||
if (argUser == null) | ||||||
{ | ||||||
argUser = arg; | ||||||
promptUser = true; | ||||||
} | ||||||
else | ||||||
{ | ||||||
if (!arg.equals("?")) | ||||||
promptUser = false; | ||||||
argPassword = arg; | ||||||
} | ||||||
} | ||||||
|
||||||
if (promptUser) | ||||||
{ | ||||||
System.out.print("Username"); | ||||||
if (StringUtil.isNotBlank(argUser)) | ||||||
System.out.printf("[%s]", argUser); | ||||||
System.out.print(": "); | ||||||
|
||||||
BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); | ||||||
String inputUser = input.readLine(); | ||||||
if (StringUtil.isNotBlank(inputUser)) | ||||||
argUser = inputUser; | ||||||
|
||||||
System.out.print("Password: "); | ||||||
argPassword = input.readLine(); | ||||||
if (StringUtil.isBlank(argPassword)) | ||||||
{ | ||||||
System.err.println("ERROR: blank passwords not supported"); | ||||||
System.exit(1); | ||||||
} | ||||||
} | ||||||
else if (StringUtil.isBlank(argUser)) | ||||||
{ | ||||||
System.err.println("Usage - java " + Password.class.getName() + " [<user>] <password>"); | ||||||
System.err.println("If the password is ?, the user will be prompted for the password"); | ||||||
System.err.printf("Usage - java %s [<user>] <password> --prompt%n", Password.class.getName()); | ||||||
System.err.printf("Argument options:%n"); | ||||||
System.err.printf(" %s%n", Password.class.getName()); | ||||||
System.err.printf(" No arguments, will show this help%n"); | ||||||
System.err.printf(" %s myusername%n", Password.class.getName()); | ||||||
System.err.printf(" username only, will prompt for entries%n"); | ||||||
System.err.printf(" %s myusername ?%n", Password.class.getName()); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
System.err.printf(" username with question mark password, will prompt for entries%n"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
System.err.printf(" %s myusername secretpassword%n", Password.class.getName()); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
System.err.printf(" username with password, will produce obfuscation results%n"); | ||||||
System.err.printf(" %s --prompt%n", Password.class.getName()); | ||||||
System.err.printf(" will prompt for entries%n"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
System.exit(1); | ||||||
} | ||||||
String p = arg[arg.length == 1 ? 0 : 1]; | ||||||
Password pw = new Password(p); | ||||||
System.err.println(pw.toString()); | ||||||
|
||||||
Password pw = new Password(argPassword); | ||||||
System.err.println(obfuscate(pw.toString())); | ||||||
System.err.println(Credential.MD5.digest(p)); | ||||||
if (arg.length == 2) | ||||||
System.err.println(Credential.Crypt.crypt(arg[0], pw.toString())); | ||||||
System.err.println(Credential.MD5.digest(argPassword)); | ||||||
if (StringUtil.isNotBlank(argUser)) | ||||||
System.err.println(Credential.Crypt.crypt(argUser, pw.toString())); | ||||||
System.exit(0); | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.