Refactored to use just one getCredential method
This commit is contained in:
parent
8e17fd2848
commit
ea057ec8d4
@ -4,17 +4,31 @@ import java.io.Console;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class credentialsProcessor {
|
public class credentialsProcessor {
|
||||||
public static String getUsername(String thisPrompt) {
|
public static String getCredential(String thisPrompt, int thisLength, boolean isSecret) {
|
||||||
|
String thisReturn = null;
|
||||||
|
if (isSecret)
|
||||||
|
{
|
||||||
|
Console console = System.console();
|
||||||
|
char[] charValue = console.readPassword(thisPrompt);
|
||||||
|
while (charValue != null && charValue.length < thisLength)
|
||||||
|
{
|
||||||
|
charValue = console.readPassword(thisPrompt);
|
||||||
|
}
|
||||||
|
thisReturn = String.copyValueOf(charValue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
Scanner myObj = new Scanner(System.in);
|
Scanner myObj = new Scanner(System.in);
|
||||||
System.out.print(thisPrompt);
|
System.out.print(thisPrompt);
|
||||||
String varEntry;
|
thisReturn = myObj.nextLine();
|
||||||
varEntry = myObj.nextLine();
|
while (thisReturn != null && thisReturn.toString().length() < thisLength)
|
||||||
return varEntry;
|
{
|
||||||
|
System.out.print(thisPrompt);
|
||||||
|
thisReturn = myObj.nextLine();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static char[] getPassword(String thisPrompt) {
|
return thisReturn;
|
||||||
Console console = System.console();
|
|
||||||
char[] password = console.readPassword(thisPrompt);
|
|
||||||
return password;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user